New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrap code block HTML table in a div element #1903
Conversation
Syntax highlighted code blocks are written out as HTML tables which are impossible to format via styles for different screen widths. This means that pandoc generated pages with code blocks must have a fixed minimal width, making them hard to read on narrower screens. Wrapping the table in a `<div>` allows formating a code block that will have a horizontal scroll bar if the content doesn't fit the screen width, by adding the following style: div.sourceCode { overflow-x: auto; } This enables pandoc to generate responsive HTML pages.
Here's an example of a page generated with the modified pandoc: https://microsoft.github.io/bond/manual/bond_cpp.html. When displayed on small screen (or narrow browser window) some of the code blocks will have horizontal scroll bar while the regular text will adjust to browser window width. |
interesting! Microsoft uses Haskell. |
Really? Could you elaborate or post an example to a jsfiddle or similar? Note that it's actually the |
Here's an example: http://jsfiddle.net/jdxpbd6o/ |
My guess is that tables don't take well to the CSS overflow scrollbar property, or at least that it has poor browser support. Note that you can easily use filters to wrap all the code block elements around a div. |
Yes, tables violate a lot of CSS rules. I'm not familiar with filters. Do you have some pointers? Does that allow having a special class on div surrounding code blocks? |
You can read a bit more about filters here1. It should be very easy to On Thu, Jan 29, 2015 at 4:10 AM, Adam Sapek notifications@github.com
|
Thanks. That's pretty neat. So the idea is to insert On a more general note, is pandoc the right tool for what I'm doing: converting software documentation to HTML? Pandoc doesn't seem focused on easy customization of the HTML output. The filters look very powerful but it is a very roundabout way to "template" HTML output... |
In this case it would probably be easier to inject a pandoc Pandoc should be suited for that. Usually it is enough to specify a stylesheet to personalise your documentation. Occasionally it is necessary to use a simple filter if you want fine-grained control. If there is anything you are finding particularly troublesome then please ask. |
@sapek You could also use CSS to set btw, it might be better for pandoc to not use a table here anyway, since it's not a semantic table. divs and some CSS (even |
@mb21 This is not as good because the block always has a disabled horizontal scroll bar, even when it is not needed. It would look rather ugly, especially with many small code blocks. Do you guys see a drawback of wrapping code blocks in a |
(there's CI environments that don't have some sort of rudimentary Python?) Well if resource really is a issue then you can always output the JSON representation and manipulate the intermediate DOM in whatever scripting environment you need, then feed it back into Pandoc to convert to HTML. I guess there's technically no problem with wrapping code blocks in div. It's just that everyone probably have their own needs for some kind of tiny tweak in the reading/writing behavior, and filters were supposed to be the solution for all that. |
@timtylin To me filters make sense for adding something that is not needed by everyone (the |
I don't see any problem with wrapping in a div by default. |
Does the change look OK or do you guys want me to change something? |
Some thoughts: Wouldn't it make more sense to put this in jgm/highlighting-kate? That would also give us the possibility of using the div wrapper only when line numbers (and hence tables) are needed, preserving the simpler structure for the other cases. (Though I'm not sure this would be better.) Further thought: perhaps we should replace the table with something else (again, this would be a change in jgm/highlighting-kate). I'm open to suggestions here; we just need something that will reliably preserve alignment of line numbers with lines, and work well across all browsers in common use. At the time I wrote highlighting-kate, this meant using tables, but maybe now two side-by-side divs would work? |
I also thought about putting this in highlighting-kate. The only advantage of always wrapping code in a |
I just had another idea. What if we put all code blocks inside |
Yes, |
I don't have the change ready. If you'd like to prepare it, go ahead. +++ Adam Sapek [Mar 07 15 18:26 ]:
|
Here's the change in |
This ensures that all code blocks will be wrapped in a div with class sourceCode. Also, the default highlighting CSS now adds `div.sourceCode { x-overflow: auto; }`, which means that code blocks (even with line numbers) will acquire a scroll bar on screens too small to display them (e.g. mobile phones). See #1903 and jgm/highlighting-kate#65.
This reverts the change in a9c79de wrapping all blocks in a pre element. (That was bad because pres are only supposed to contain flow-level content.) Instead we now wrap in a div. The default CSS now includes "x-overflow: auto" for the div, so that a scroll bar will appear on small screens. See jgm/pandoc#1903 and #65 for background.
Syntax highlighted code blocks are written out as HTML tables which are
impossible to format via styles for different screen widths. This means
that pandoc generated pages with code blocks must have a fixed minimal
width, making them hard to read on narrower screens.
Wrapping the table in a
<div>
allows formating a code block that willhave a horizontal scroll bar if the content doesn't fit the screen
width, by adding the following style:
This enables pandoc to generate responsive HTML pages.