Exclude block of codes from parsing?

180 prikaza
Preskoči na prvu nepročitanu poruku

XWisdom

nepročitano,
20. apr 2012. u 09:56:1320. 4. 2012.
za highlight.js
Hi,

is there anyway to exclude blocks of codes from parsing or to have
them parsed with a default style? The problem is that HTTP requests
and response seems to be parsed incorrectly, for example:

GET /route-test HTTP/1.1
Accept: text/html
Cache-Control: no-cache
Pragma: no-cache
User-Agent: Java/1.6.0_31
Host: test.com
Connection: keep-alive

I would like the whole block to be parsed as maybe "string" or
"constant". Is it possible?

Best regards,

Peter

Ivan Sagalaev

nepročitano,
20. apr 2012. u 14:41:4820. 4. 2012.
za highl...@googlegroups.com
On 04/20/2012 06:56 AM, XWisdom wrote:
> is there anyway to exclude blocks of codes from parsing or to have
> them parsed with a default style?

Yes, set class="no-highlight" to them. This is documented under the
"Heuristics" section in the README.

Aahan Krish

nepročitano,
20. apr 2012. u 20:47:3920. 4. 2012.
za highl...@googlegroups.com

XWisdom

nepročitano,
21. apr 2012. u 02:12:2421. 4. 2012.
za highlight.js
Thanks for your answer, I've missed that section in readme. I've tried
using a <span class="no-highlight"> inside a <code> block but it
didn't work, so I guess that's not supported?

On 21 Apr, 02:47, Aahan Krish <geekpant...@gmail.com> wrote:
> README:http://softwaremaniacs.org/soft/highlight/en/description/

Ivan Sagalaev

nepročitano,
21. apr 2012. u 02:31:5621. 4. 2012.
za highl...@googlegroups.com
On 04/20/2012 11:12 PM, XWisdom wrote:
> Thanks for your answer, I've missed that section in readme. I've tried
> using a<span class="no-highlight"> inside a<code> block but it
> didn't work, so I guess that's not supported?

The "no-highlight" class works on an element that contains the code
(which is `<code>` by default). It just tells highlight.js to ignore the
code in this element and not try to highlight it.

But frankly I can't imagine what is it that you tried to achieve by
putting "no-highlight" somewhere inside the code block. May be there's
way to do that differently so please explain the goal!

XWisdom

nepročitano,
21. apr 2012. u 02:41:3821. 4. 2012.
za highlight.js
Hi Ivan,

my problem is that the code I'm trying to highlight consist of
different languages and formats such as HTTP requests and responses,
JSON data, XML etc. But the parser parse everything as "ruby". Because
the code is coming from an external source, I can't tell them to add
the appropriate <code class=""> to each section, so I'm just trying to
surround the blocks that parser don't understand (HTTP Response/
Requests) with "no-highlight" so it doesn't get parsed.

Best regards,

Peter

Ivan Sagalaev

nepročitano,
21. apr 2012. u 02:52:2221. 4. 2012.
za highl...@googlegroups.com
On 04/20/2012 11:41 PM, XWisdom wrote:
> my problem is that the code I'm trying to highlight consist of
> different languages and formats such as HTTP requests and responses,
> JSON data, XML etc. But the parser parse everything as "ruby". Because
> the code is coming from an external source, I can't tell them to add
> the appropriate<code class=""> to each section, so I'm just trying to
> surround the blocks that parser don't understand (HTTP Response/
> Requests) with "no-highlight" so it doesn't get parsed.

OK, I got it. It won't work this way because highlight.js highlights a
single block of code with a single language. So if you have something like:

<code>
// this is some json:
{ ... }

// this is HTML:
&lt;div&gt; ... &lt;/div&gt;
</code>

It's not going to work. The only way to highlight snippets in different
languages is to have each snippet in its own container (no matter which
tag). Is this how you have them? Even better, could you paste a short
example here?

Aahan Krish

nepročitano,
21. apr 2012. u 03:07:0521. 4. 2012.
za highl...@googlegroups.com
Have you tried this?

<pre class="no-highlight"> .... </pre>

Ivan said: The "no-highlight" class works on an element that contains the code (which is `<code>` by default). It just tells highlight.js to ignore the code in this element and not try to highlight it.

So, the above solution may not work, but still, do try it (I have no chance to test it now).

XWisdom

nepročitano,
21. apr 2012. u 03:16:5621. 4. 2012.
za highlight.js
Here is some example code:

<code>
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Date: Sat, 14 Apr 2012 18:01:56 GMT
Content-Type: application/vnd-
riv.crm.scheduling.v1_1+json;charset=UTF-8
Content-Length: 1405

{
"json":[
{
"key":"value1",
"key2":"value2",
"key3":"value3"
}
]
}
</code>

Aahan Krish

nepročitano,
21. apr 2012. u 03:30:5121. 4. 2012.
za highl...@googlegroups.com
That shouldn't be a problem if you do it like this:

<pre><code class="no-highlight"> 

HTTP/1.1 200 OK 
Server: Apache-Coyote/1.1 
Date: Sat, 14 Apr 2012 18:01:56 GMT 
Content-Type: application/vnd- 
riv.crm.scheduling.v1_1+json;charset=UTF-8 
Content-Length: 1405 


   "json":[ 
      { 
         "key":"value1", 
         "key2":"value2", 
         "key3":"value3" 
      } 
   ] 

</code></pre>

Aahan Krish

nepročitano,
21. apr 2012. u 03:31:4121. 4. 2012.
za highl...@googlegroups.com
Disregard the code in my previous reply. Do it like this:

Ivan Sagalaev

nepročitano,
21. apr 2012. u 10:59:5821. 4. 2012.
za highl...@googlegroups.com
On 04/21/2012 12:16 AM, XWisdom wrote:
> Here is some example code:
>
> <code>
> HTTP/1.1 200 OK
> Server: Apache-Coyote/1.1
> Date: Sat, 14 Apr 2012 18:01:56 GMT
> Content-Type: application/vnd-
> riv.crm.scheduling.v1_1+json;charset=UTF-8
> Content-Length: 1405
>
> {
> "json":[
> {
> "key":"value1",
> "key2":"value2",
> "key3":"value3"
> }
> ]
> }
> </code>

Yeah� Unfortunately highlight.js is not up to the job like this.
Autodetection will be forever confused by HTTP headers and even if you
specify a language explicitly there is a chance it won't work because
those headers might break the syntax.

It's definitely an interesting use-case to solve but I have no idea
right now how, or even if it's at all feasible. So we can't help you
right now, sorry!
Odgovori svima
Odgovori autoru
Proslijedi
0 novih poruka