How to remove wikilinks and handle citatios? #9709
Unanswered
putzwasser
asked this question in
Q&A
Replies: 2 comments 6 replies
-
I think, I learned that Str isn't the right object to work with. I read about custom readers. I created this custom reader: function Reader(input, args)
-- process wiki links
local pattern = "%[%[([^%|%#%]]+)%#?[^%]]*%|?([^%]]*)%]%]"
input = tostring(input):gsub(pattern, function(main, alias)
if alias == "" then
return main
else
return alias
end
end)
-- Removes comments
input = input:gsub("%%%%[^%%]+%%%%", "")
local blocks = pandoc.read(input, 'markdown').blocks
return pandoc.Pandoc(blocks)
end This works "fine" (in a limited test) with pandoc: # Introduction
%% Comment %%
%%
Multiline Comment
%%
This is a book %%inline comment%% created from [[markdown]] and executable code.
See [[@knuth84]] for additional discussion of [[my link to literate programming|literate programming]].
See Knuth [-[[@knuth84]]] also for something else.
# Introduction (more wiki link syntax)
This is a book %%inline comment%% created from [[markdown#heading|markdown]] and [[executable#otherheading]] code.
See [[@knuth84]] for [[additional#^somesection]] discussion of [[my link to literate programming#^section|literate programming]].
See Knuth [-[[@knuth84]], 54] also for something else. Renders via pandoc
To this: This looks great so far. The problem is: I can't use the reader with quarto: project:
type: book
book:
title: "Test"
author: "Norah Jones"
date: "17.5.2024"
chapters:
- index.qmd
- intro.qmd
- summary.qmd
- references.qmd
bibliography: references.bib
format:
pdf:
documentclass: scrreprt
from: "/tmp/test/readobsidian.lua" Output$ quarto render
[1/4] index.qmd
[2/4] intro.qmd
[3/4] summary.qmd
[4/4] references.qmd
pandoc
to: latex
from: /tmp/test/readobsidian.lua
output-file: index.tex
standalone: true
toc: true
number-sections: true
top-level-division: chapter
pdf-engine: xelatex
variables:
graphics: true
tables: true
default-image-extension: pdf
metadata
crossref:
chapters: true
documentclass: scrreprt
papersize: letter
classoption:
- DIV=11
header-includes:
- '\KOMAoption{captions}{tableheading}'
block-headings: true
bibliography:
- references.bib
title: Test
author: Norah Jones
date: 17.5.2024
Error running Lua:
/opt/quarto/share/pandoc/datadir/_format.lua:175: Warning: Invalid format /tmp/test/readobsidian.lua. Assuming 'markdown'.
stack traceback:
/opt/quarto/share/pandoc/datadir/_format.lua:175: in function '_format.parse_format'
/opt/quarto/share/pandoc/datadir/readqmd.lua:135: in function 'readqmd.readqmd'
/opt/quarto/share/filters/qmd-reader.lua:13: in function 'Reader' If I make from a relative path
|
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Hi,
I'm doing my first steps with quarto. I am using obsidian and, thus, have wiki links in the documents I want to process using quarto. Wiki links I use are:
[[link to a obsidian note]]
[[link to a obsidian note|some alias]]
Additionally, I create markdown literature notes for the sources I'll quote. I link these in my documents, too.
My literature notes are titled after the bibliography cite key:
/Obsidian/Vault/Literature-Notes/@citekey.md
In a text I link these like this:
For quarto I'd use an additional set of brackets:
So, basically, I want to get rid of the wiki links (mostly the
[[
/]]
) before quarto/Pandoc does anything.As quarto doesn't support wiki links OOTB I tried to create a Lua filter to remove the wiki links:
The Lua script itself seems to work correctly (see further below).
But in the quarto/Pandoc context this doesn't really work. So, please help me fix that.
Minimal working example
remove-wikilinks.lua
, paste the contents from above and add it to_quarto.yaml
intro.qmd
Output
The output is:
This is completely off.
Please help me understand why the output isn't as I expected it to be.
I'm having a hard time understanding this, because the Lua code seems to be working:
Lua Code Snippet
https://www.jdoodle.com/ia/12JH
Code Snippet's Output
The above snippet creates the output I'd like quarto to process:
Beta Was this translation helpful? Give feedback.
All reactions