org-page icon indicating copy to clipboard operation
org-page copied to clipboard

better exporting of #+BEGIN_SOURCE blocks

Open shackra opened this issue 9 years ago • 14 comments

org-mode makes silly things for rendering code block when exporting to HTML. The thing is I made some questions at emacs stackexchange, and a very loving and kind developer pasted his code, all necesary elisp code, to export such code blocks as <pre><code> tags and compatible with highlight.js

Here is his answer with complete code snippets.

Hence, I was thinking that this project would make a good use of such code snippets if they were integrated. I already enjoy the benefits of such change, as for instance: the exported source blocks are responsive-design friendly.

shackra avatar Mar 11 '15 22:03 shackra

Thanks for the link. However, org-page does not use org-mode's code block rendering(insert so many ugly tags), instead, org-page will export code blocks in plain text, and then render these blocks with prettify.js.

sillykelvin avatar Mar 13 '15 06:03 sillykelvin

Uh, that wasn't the case for me with org-page until I integrated the code I'm linking

shackra avatar Mar 13 '15 19:03 shackra

Could you please paste a link here to the generated html source by that code snippet?

sillykelvin avatar Mar 17 '15 15:03 sillykelvin

sure! I have a begginers tutorial about Emacs, I have a lot of code blocks on it, check it if you want.

You can also check the author of those code snippets blog, here

shackra avatar Mar 17 '15 19:03 shackra

I viewed the source, the code below is generated by org-page:

<pre class="src src-C++">
//...
</pre>

the code below is generated by the snippet you mentioned:

<pre><code class="lang-emacs">
;; ...
</code></pre>

Seems the only difference is the extra <code> tag?

BTW, your site's theme is really nice. :-)

sillykelvin avatar Mar 19 '15 05:03 sillykelvin

El 18 de marzo de 2015 a las 11:32 PM Kelvin Hu [email protected] escribió:

I viewed the source, the code below is generated by org-page:

<pre class="src src-C++">
//...
</pre>

the code below is generated by the snippet you mentioned:

<pre><code class="lang-emacs">
;; ...
</code></pre>

Seems the only difference is the extra <code> tag?

Well, yeah, that and some matching names since highlight.js may not have highlighters for some languages supported in Emacs through major modes... but I'm not sure.

BTW, your site's theme is really nice. :-)

haha, Thank you! I'm learning web design!

Pax et bonum. Jorge Araya Navarro. ES: Diseñador Publicitario, Programador Python y colaborador en Parabola GNU/Linux-libre EN: Ads Designer, Python programmer and contributor Parabola GNU/Linux-libre EO: Anonco grafikisto, Pitino programalingvo programisto kai kontribuanto en Parabola GNU/Linux-libre https://es.gravatar.com/shackra

shackra avatar Mar 19 '15 06:03 shackra

Currently org-page uses prettify.js to render code blocks, and the <pre>...</pre> tag pair serves well for that, sorry that if there is no obvious benefit of the extra <code>...</code> tag pair, I prefer to no change.

However, you can keep that code snippet for your own generation. :-)

sillykelvin avatar Mar 21 '15 16:03 sillykelvin

There is one benefit: when the code is more width than the area where it is wrapped, a scroll bar is offered by the web browsers. This is critical for responsive design!

El 21 de marzo de 2015 10:35:53 CST, Kelvin Hu [email protected] escribió:

Currently org-page uses prettify.js to render code blocks, and the <pre>...</pre> tag pair serves well for that, sorry that if there is no obvious benefit of the extra <code>...</code> tag pair, I prefer to no change.

However, you can keep that code snippet for your own generation. :-)


Reply to this email directly or view it on GitHub: https://github.com/kelvinh/org-page/issues/110#issuecomment-84388388

Enviado desde mi teléfono con K-9 Mail.

shackra avatar Mar 21 '15 17:03 shackra

Isn't the scroll bar controlled by CSS?

sillykelvin avatar Mar 24 '15 15:03 sillykelvin

If you only use the

 tag, no, no scroll bar is shown

El 24 de marzo de 2015 09:06:49 CST, Kelvin Hu [email protected] escribió:

Isn't the scroll bar controlled by CSS?


Reply to this email directly or view it on GitHub: https://github.com/kelvinh/org-page/issues/110#issuecomment-85543726

Enviado desde mi teléfono con K-9 Mail.

shackra avatar Mar 24 '15 17:03 shackra

One additional problem is that prettify.js does not seem to support emacs-lisp. See e.g. http://blog.pschorf.com/blog/2016/02/28/spacemacs-blogging/ . In the first code block it thinks that 'org-page-theme-kactus starts a string.

cpaulik avatar Mar 01 '16 13:03 cpaulik

I find two related issues at prettify.js' repo: https://github.com/google/code-prettify/issues/159 https://github.com/google/code-prettify/issues/176 Please have a try to see if it works.

sillykelvin avatar Mar 02 '16 05:03 sillykelvin

Thanks.

Exporting emacs lisp as lisp and adding <script src='http://google-code-prettify.googlecode.com/svn/trunk/src/lang-lisp.js' type='text/javascript'></script> to the template fixes the string issue.

I'm not sure how big the differences between lisp and emacs-lisp are and if this could be a source of problems.

cpaulik avatar Mar 02 '16 14:03 cpaulik

Hi! I am using highlightjs in my website built with org-page.

My solution was reduce main.js to:

$(document).ready(function() {
  $('pre').each(function(i, block) {
    var self = $(this);
    self.removeAttr('class');
    self.html('<code>' + self.html() + '</code>');
    hljs.highlightBlock(block);
  });
});

This code:

  • Remove class attribute from <pre> HTML Tag
  • Put <code> between <pre> and his content.
  • hljs.highlightBlock(block); - from highlightjs usage - Custom Initialization section.

And now highlightjs works for pre.src and pre.example. I do not use prettify anymore.

In time: Kelvin Hu thank you so much for org-page.

lnlsn avatar Apr 07 '16 22:04 lnlsn