2

I have a markdown file which looks like this:

# Sors inmotusque emicat de ope onus in

## Virgo cupidusque timet stant

Lorem *markdownum*, premeret, atque expresso contraria ossibus, et virgo et
speciem castris nostris. **Obliquis** adest, e quantum mirata me crinem gentis
clamabat versae fretoque sinistris. Speciem omne inpia illi mundi arbor virgis
misit aliquid, alas et lacertos restatque roganti. Primae patriosque, gravitate
omnes. Manu illa nec, qua est, ex vero inmittitur ursos, AI.

> Mare meritorum pellite corpore [Caras](http://cernis.com/). Nati sed aut
> moritura fluit crescitque Cereale nactusque exorabilis venias patruelibus
> arbore et invitat perfudit motatque adversi Zetesque sibi. Rectoque genua, per
> indefletaeque icta et nitentia arserat ignara caede nati semesaque. Iacentes
> lumina nutrix confluat cum positoque tuta, et quod et sanguine.

Iam pavet hac cum visis faxo undis volucres caligine odium, ubi crimen praelatus
munere strepitum fortuna solum **iunctis**! Propositique signa natas poenam
somnus quinque obstitit; iunxit si ubi in en arma,
[spatiis](http://iamqueaquarum.net/) successerat ripas. Feruntur forte moram
fore finem, piae perque **aut retia mollibat**, nec. **In obliquis**: situsque
lacerata nomine propera nubilus vincemur vestigia *consuetissima nititur
interea* repugnat.

I have two output formats: HTML and LaTeX.

How can I accomplish that only parts of the markdown convert to HTML/LaTeX?

Let's say the first paragraph of the markdown file should appear in the HTML file but not in the LaTeX file and the last paragraph should appear in the LaTeX file but not in the HTML file.

0

1 Answer 1

3

You can write a filter that deletes a fenced div, depending on the output format:

# Sors inmotusque emicat de ope onus in

## Virgo cupidusque timet stant

:::: onlyhtml
Lorem *markdownum*, premeret, atque expresso contraria ossibus, et virgo et
speciem castris nostris. **Obliquis** adest, e quantum mirata me crinem gentis
clamabat versae fretoque sinistris. Speciem omne inpia illi mundi arbor virgis
misit aliquid, alas et lacertos restatque roganti. Primae patriosque, gravitate
omnes. Manu illa nec, qua est, ex vero inmittitur ursos, AI.
::::

> Mare meritorum pellite corpore [Caras](http://cernis.com/). Nati sed aut
> moritura fluit crescitque Cereale nactusque exorabilis venias patruelibus
> arbore et invitat perfudit motatque adversi Zetesque sibi. Rectoque genua, per
> indefletaeque icta et nitentia arserat ignara caede nati semesaque. Iacentes
> lumina nutrix confluat cum positoque tuta, et quod et sanguine.

:::: onlylatex
Iam pavet hac cum visis faxo undis volucres caligine odium, ubi crimen praelatus
munere strepitum fortuna solum **iunctis**! Propositique signa natas poenam
somnus quinque obstitit; iunxit si ubi in en arma,
[spatiis](http://iamqueaquarum.net/) successerat ripas. Feruntur forte moram
fore finem, piae perque **aut retia mollibat**, nec. **In obliquis**: situsque
lacerata nomine propera nubilus vincemur vestigia *consuetissima nititur
interea* repugnat.
::::

The filter, called onlyparts.lua:

function Div(el)
  if el.classes[1] == "onlyhtml" and not FORMAT:match 'html' then
    el.content = ""
  elseif el.classes[1] == "onlylatex" and not FORMAT:match 'latex' then
    el.content = ""
  end
  return el
end

Now you can use the filter like this:

$ pandoc in.md --lua-filter=./onlyparts.lua -o out.html

enter image description here

Or that:

$ pandoc in.md --lua-filter=./onlyparts.lua -o out.pdf

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.