[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Inline markup: How does org identify nested code/verbatim?
From: |
c.buhtz |
Subject: |
Inline markup: How does org identify nested code/verbatim? |
Date: |
Sun, 29 Jan 2023 18:05:14 +0000 |
Hi folks,
this is a question about org(mode) development itself.
It is magic to me how you do this. ;) And I would like to learn it
because I do write kind of an org parser in Python.
Here is a nested code-in-verbatim text.
This =is ~code~ in verbatim= text.
Exporting this to html (via org-html-export-as-html)
This <code>is ~code~ in verbatim</code> text.
Awsome! :D
The point is myself I'm able to identify code or verbatim with regex
including three catch groups for the content before, between and
after the inline markers.
for verbatim: "(^|[ .,;:\-?!({\"'])=(.*?)=([ .,;:\-?!)}\"']|$)"
for code: "(^|[ .,;:\-?!({\"'])~(.*?)~([ .,;:\-?!)}\"']|$)"
But they don't work together. In the example above I need to use the
verbatim regex first to make it right.
If I would use the code regex first it wouldn't work because it would
find the ~code~ but without knowing that it is surrounded by ~verbatim~.
I don't know what my users inputs to my software: verbatim in code or
code in verbatim. So I have to figure out which regex to use first.
How does org solve this problem? I don't need a full working solution
but just an idea.
One approach in my mind is to run both regex separate and then compare
the results "somehow":
Verbatim: ['This', ' ', 'is ~code~ in verbatim', ' ', 'text.']
Code : ['This =is', ' ', 'code', ' ', 'in verbatim= text.']
"Somehow"!
Another approach in my mind is to do something I would call nested
regex. Constructing a regex pattern looking for verbatim with code in
it. And the other way around of course.
- Inline markup: How does org identify nested code/verbatim?,
c.buhtz <=