Pandoc Markdown: ignore text in PDF (but include in HTML) Updated?

筅森魡賤 提交于 2019-11-28 04:52:18

问题


This question of how to include text that will appear in html but not pdf has been answered twice (LaTeX multicolumn block in Pandoc markdown and Pandoc markdown: Omit text in PDF version but include in HTML version) and I applied the solution recommended:

Here is the source:

My text.

<div>
This will be ignored in non-HTML output
</div>

Other text

The command I used was: pandoc essai.md --from=markdown-markdown_in_html_blocks -o essai.pdf

Yet the text between the <div>tags is still displayed in the pdf file.

Am I missing something obvious? Or has the behaviour of pandoc changed since 2013/2014 (my version is 1.19 of 2016)? If yes, what would the solution be?


回答1:


I know you asked for a solution that works with pandoc 1.19, but for completeness, here is one which is a bit cleaner but only works with pandoc 2.0 and later:

There is a new raw_attribute extension, which allows to do the following:

`text in html`{=html}
`text in pdf`{=latex}

It is enabled in pandoc markdown per default.




回答2:


I found an answer: add the -native_divs extension.

This way:

$ pandoc essai.md --from=markdown-markdown_in_html_blocks-native_divs -t latex
My text.

other text

My understanding is that pandoc has started interpreting <div> items as "native" elements, i.e. represented in the AST, which causes the interesting side effect that a <p> is added in html. This behaviour needs to be deactivated in order to obtain the desired effect.

If someone has a better solution or a better explanation, please let me know.



来源:https://stackoverflow.com/questions/48083724/pandoc-markdown-ignore-text-in-pdf-but-include-in-html-updated

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!