-
Notifications
You must be signed in to change notification settings - Fork 60
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
Wiki-links not removed when exporting from markdown #71
Comments
Hi, This is expected behaviour. When you change this setting, you are choosing between Obsidian's markdown features and Pandoc's markdown features. If you want Pandoc citations you have to give up Obsidian wiki-links, and vice versa. There's no easy way to get the best of both worlds unfortunately. I realise this setting is poorly worded, so I will probably change it in the future. |
Hi, thanks for responding. I understand the issue, but I was thinking it might still make sense to work around it. I wrote this very barebones python filter that removes the brackets upon export, which works as a patchy solution for now https://gist.github.com/maybemkl/d9be15bcabadaa19d2ca50c87b59a92e |
Yes, that's a fair point - this is one case where it's easy to fix formatting, but I can't fix formatting in general. I'll take a look at this in the next release |
Hello @OliverBalfour
Here is what my command line looks like:
(obviously you have to download the zotero.lua file for it to work) Here what it looks like on a sample page : Markdown page in Obsidian, with both Obsidian stuff and citations: Resulting docx file: I did not test it extensively yet, but for now it seems to work very well. I know it's kinda hacky but I've seen much hackier code before. If it can give you ideas. Thanks again, Felix |
Hi @felixchenier your temporary proposal looks great, but I would be loosing footnotes - any idea for that ? |
Hi @Limezy
But I didn't try it. And for highlights, it may be the same thing but for escaped equals:
But I also didn't try it. It may (will) break something, somewhere, at some moment, that's for sure! Good luck |
a usable lua-filter function Str (str)
return (str.text
:gsub('%[%[', '')
:gsub('%]%]', ''))
end |
Wow that's great @wenbopeng |
For whoever is interested, my current filter : function Str (str)
return (str.text
:gsub('%[%[', '')
:gsub('%]%]', ''))
end Now only waiting for the plugin to manage transclusions ! |
@Limezy |
https://regex101.com/r/jCiF1r/1 seems to solve most cases for me as of now. But there must be a more accessible way no? :D
|
@bvorak @jankap my current lua filter is now a bit crazy. It will replace "[[ANYTHING|D]]" by "D" "A", "B", "C" or "D" markdown markups will be converted to LaTeX equivalent markup. You can probably easily change these behaviours using my example as a starting point. Filter one
Filter two
|
Credits to https://github.com/tarleb for getting me started with the wikilink syntax detection |
@Limezy how do you call it? Edit: |
@Limezy thanks for the terrific work on creating a full Lua solution. However, I found Albert's script structure quite long and hard to understand. I created a simplified alternative script preserving only the first two rules:
I'm exploiting the fact that in Obsidian the link label can't have formatting and the only elements between the brackets are strings and spaces. Moreover, multiple spaces count as one, so you can suppress inline elements by replacing them with spaces. I added some logic to remove the section anchors (
Here's the script: -- wikilinks.lua
-- remove wikilinks identifiers and replace them with the link text
function clean (text)
return text
:gsub("%[%[([^|]-)%]%]", "%1") -- remove simple wikilinks
:gsub("%[%[.-|(.-)%]%]", "%1") -- remove wikilinks with custom text
end
function Blocks(blocks)
for _,elem in pairs(blocks) do
if elem.t == "Para" then
local start = nil
for i, inline in ipairs(elem.content) do
if inline.tag == "Str" then
-- remove links identifiers
inline.text = inline.text:gsub("^%^%w+", "")
-- Pandoc always parse the escapes, so there is no way to tell
-- ^ and \^ apart
end
-- select range corresponding to wikilink and subsitute it
if inline.tag == "Str" and inline.text:match("%[%[") then
start = i
end
if inline.tag == "Str" and inline.text:match("%]%]") and start then
local result = elem.content[start].text
for j = start+1, i do
if elem.content[j].tag == "Str" then
result = result .. elem.content[j].text
else -- if it's not a string, it's a Space
result = result .. " "
end
elem.content[j] = pandoc.Space()
end
elem.content[start].text = clean(result)
start = nil
end
end
end
end
return blocks
end |
Sorry to revive this old post, but since 2023/01/18 Pandoc offers 2 extensions, For example :
|
When I changed the setting "Export files from HTML to Markdown" from HTML to Markdown, all the functionality for removing [[wiki-links]] formatting in the output PDF stops working.
The text was updated successfully, but these errors were encountered: