How to embed code properly

17 views
Skip to first unread message

Albert Vonpupp

unread,
Nov 24, 2015, 9:49:12 PM11/24/15
to Hyde
Hello,

I am writing a couple of posts on how to build a multilanguage site with Hyde. To do so I need to embed jinja code and Hyde seems to get confused while processing this.

How do I do this properly? I am trying [1] to include github code directly using javascript, however I have read that this might not work properly over RSS (I haven't tried that yet).

What do you usually solve this kind of things? I would like code to be highlighted and if possible with line numbers.

Thanks a lot.

Lakshmi

unread,
Nov 24, 2015, 11:42:22 PM11/24/15
to Hyde
Hi Albert,

> Hyde seems to get confused

You can use the `raw` tag to escape jinja code:
http://jinja.pocoo.org/docs/dev/templates/#escaping

I have always included source in the template (inline or using template includes).   The trouble with embedding code directly is that the code and the content may go out of sync with each other if we are not pointing to a particular blob.   If we are indeed pointing to a blob, isn't it better to simply include the appropriate portions of the source and use pygments for highlighting?  No need for all the JS bloat on the page.

You can setup line numbers with the following in site.yaml:

```
syntax:
  options:
    linenos: table
```



Cheers
Lakshmi

Albert Vonpupp

unread,
Nov 25, 2015, 12:17:34 PM11/25/15
to Hyde
Hello Lakshmi,

As usual, thank you very much for your reply!

I tried three options:
- The first one is "raw" [1], it escapes fine however it does not highlight anything.
- The second option is "syntax raw" [2]. This doesn't work so probably it doesn't exist. I was just checking out.
- The third option is "include" [3]. I did not commit this since the include statement breaks the generation process, I'm not sure why.

You can see [1] and [2] live on the [site], searching for the "The metadata of a post" section.

So the only working option is the first one however the code does not get formated as it should. Is this normal? Is there an easier way to get the raw text formated?

Thank you.

[3]: {% include '/home/av/hyde-test/hyde-bootstrap-template/content/en/blog/2015-11-happy-post.html' %}

Lakshmi Vyasarajan

unread,
Nov 25, 2015, 6:26:06 PM11/25/15
to hyde...@googlegroups.com
Hi Albert,

I didn't have the time to go through this in detail, but have you tried:

```
{% sytnax %}
{% raw %}
...
...

{% endraw %}
{% endsyntax %}

Cheers
Lakshmi

--
You received this message because you are subscribed to the Google Groups "Hyde" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hyde-dev+u...@googlegroups.com.
To post to this group, send email to hyde...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hyde-dev/0e983957-189a-48ba-9c9c-efa47b6591e1%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Albert Vonpupp

unread,
Nov 26, 2015, 2:51:53 PM11/26/15
to Hyde
Oh my... I actually thought of that but from your last message I misunderstood the html formatting with pygments, so I thought I had to use pygments directly. I'm glad there is an easy solution.

Thank you very much Lakshmi! I will review the two posts I wrote and I will send them to the list for general comments.

Best regards.
Reply all
Reply to author
Forward
0 new messages