I exported a notebook to markdown (which is great), but I found that the files don't have links to other files like they were in Siyuan.
So, is there anyway to make markdown exports have links to other files?
I exported a notebook to markdown (which is great), but I found that the files don't have links to other files like they were in Siyuan.
So, is there anyway to make markdown exports have links to other files?
Here's the before and after comparison.
Before:
# Networking
The most important things to know are the networking protocols.
* [TCP](siyuan://blocks/20231110002225-jzlfmvr)
* [UDP](siyuan://blocks/20231111114912-9gi1l0p)
* [HTTP](siyuan://blocks/20231110002250-b9w413n)
* [TLS](siyuan://blocks/20231111114933-oti4rz4)
* [WebSockets](siyuan://blocks/20231111115839-xw23n4k)
* [WebRTC](siyuan://blocks/20231111114916-nevtkga)
After:
# Networking
The most important things to know are the networking protocols.
* [TCP](/Networking/TCP.md)
* [UDP](/Networking/UDP.md)
* [HTTP](/Networking/HTTP.md)
* [TLS](/Networking/TLS.md)
* [WebSockets](/Networking/WebSockets.md)
* [WebRTC](/Networking/WebRTC.md)
I think there is a fairly simple solution to this, which I will describe below. I think it can be implemented as a simple Python script that does some post-processing of the exported markdown files. I will try to create a proof-of-concept script, but it will take me a few days because I am not a programmer and will need to learn some Python programming first.
In Settings > Export configure 'Ref' to 'Anchor text with block URL'. After doing this, a link to another block in a SiYuan note appears in the exported Markdown file as [Anchor text](siyuan://blocks/block-id)
.
Write a Python script that opens each exported markdown file and uses regex matching to identify all instances of [Anchor text](siyuan://blocks/block-id)
. For each instance,
Use the /api/query/sql
API endpoint to get details of the block-id
by making a query like:
{ "stmt": "SELECT * FROM blocks WHERE id='block-id'" }
In the query result, you can find the hpath
key whose value is a human readable path.
siyuan://blocks/block-id
with hpath_value.md which would be the relative path to the exported markdown file that the link points to.hpath
for that block-id), find the start of the paragraph and add an <a name="block-id"></a>
anchor at the start of the paragraph. Then, the siyuan://blocks/block-id
in the exported markdown file can be replaced by hpath_value.md#block-id
This would basically solve the problem of having correct links in the exported markdown files and additionally the exported notes can easily be converted to HTML and published e.g. with a static site generator like Hugo.
@88250 Do you see any problems with this approach? I don't understand why SiYuan does not do this already when exporting to markdown.. but in any case, a Python script that does the above can post-process the exported markdown files from SiYuan and fix all the links. What do you think?
I think the issue remains with anchor hash
for the reason that it is limited to notebook currently, meaning I cannot select rendering from Markdown to HTML from the notebook_ex > export > (selectable=Markdown/siyuan.sy.zip)
.
How would i export my notes to HTML with anchor hash
? I think I would be limited to using pandoc input.md -o output.html
, I tried it with pandoc, which succesfully creates html with link to other note, but it just opens the other note without navigation to the <span>
block, so no hash jump in browser (brave/firefox) to block.
You're welcome! I actually was too lazy to write it myself so I asked ChatGPT to do it for me and changed some mistakes in its code.
And I might as well do it for non-document blocks, I will post the solution here too.
In any case, it seems like this problem can be solved easily and be integrated into SiYuan.
I am not familiar with SiYuan code or Golang in general so someone else more familiar may make a Pull Request for this feature way faster than me.
If not, I don't mind spending some time to learn enough to build this feature into SiYuan. It's the least I can do in return for getting this amazing app for free!
Thanks @88250 @sagar and long live the open source!
Welcome to here!
Here we can learn from each other how to use SiYuan, give feedback and suggestions, and build SiYuan together.
Signup About