Commit graph

37 commits

Author SHA1 Message Date
Niklas Fasching
5464ab37d2 Fix race condition surrounding global orgWriter
Since writers are normally only used synchronously (i.e. to write one document
at a time), we don't guard modifications to their internal
state (e.g. temporarily replacing the string.Builder in WriteNodesAsString)
against race conditions.

The package global `orgWriter` and corresponding use cases of it (`org.String`,
`$node.String`) break that pattern - the writer is potentially used from
multiple go routines at the same time. This results in race conditions that
manifest as error messages like e.g.

    could not write output: runtime error: invalid memory address or nil pointer dereference. Using unrendered content.

Additionally, since we catch panics in `Document.Write`, the corresponding
stack trace is lost and dependents of go-org never know what hit them.

As using a writer across simultaneously across go routines is not a standard
pattern, we'll sync the use of the global `orgWriter` instead of trying to make
the actual writer threadsafe; less code noise for the common use case.
2023-03-12 11:28:55 +01:00
Niklas Fasching
f27340ed5e Add \ to emphasis post chars to allow immediate explicit line break
Post chars are defined in (nth 1 org-emphasis-regexp-components) in emacs org.
When I initially adapted the list of chars for go, I failed to check how it's
actually used (further down in org.el):
  (string-match (concat "[" (nth 1 erc) "\n]") (char-to-string (char-after (point))))

Due to the surrounding [] the `\\` in
  '("-[:space:]('\"{" "-[:space:].,:!?;'\")}\\[" "[:space:]" "." 1)

is actually a literal backslash, not an escape of the opening bracket I
guess. I'm not in the mood for thinking any harder about this, so let's hope
this is right. yolo.
2022-09-20 17:16:40 +02:00
Niklas Fasching
a520664dc7 emphasis: Fix reading of prev/next rune for multibyte characters 2022-06-18 16:10:19 +02:00
Niklas Fasching
c901c00166 Add non-standard ealb (east asian line break) option
See pandoc: https://pandoc.org/MANUAL.html#extension-east_asian_line_breaks
2021-07-20 22:33:28 +02:00
Niklas Fasching
d85768891c html: Support links with image descriptions
Turns out Org mode supports image links natively and we don't have to go out of
spec!

From https://orgmode.org/manual/Images-in-HTML-export.html:

[...] if the description part of the Org link is itself another link, such as
‘file:’ or ‘http:’ URL pointing to an image, the HTML export back-end in-lines
this image and links to [...]
2020-06-28 21:16:46 +02:00
Niklas Fasching
9f7e8a8fbd Implement #+MACRO 2020-04-17 16:41:06 +02:00
Niklas Fasching
47a3653d61 Fix inline src index off by one
thank god for fuzzing
2020-04-17 15:39:43 +02:00
Niklas Fasching
4b56810a65 Implement inline export blocks
https://orgmode.org/manual/Quoting-HTML-tags.html
2020-04-16 14:58:23 +02:00
Niklas Fasching
3018ace8d0 Implement inline source blocks
https://orgmode.org/manual/Structure-of-Code-Blocks.html
2020-04-16 14:58:13 +02:00
Niklas Fasching
115a8b9c1b Fix latex fragment parsing
delimiters are not always 2 in length - $ being the exception. Also we have to
make sure to handle both $ and $$ delimiters.

Not proud of this solution but can't think of anything simpler right now - will
come back to this later hopefully.
2020-01-20 18:47:26 +01:00
Niklas Fasching
9a0a9c11eb Export WriteNodesAsString on writer interface
WriteNodesAsString is simple enough to implement but exposing it is helpful in
the implementation of extending writers and we don't aim to keep writer a small
interface so let's expose it.
2019-11-02 23:44:16 +01:00
Niklas Fasching
4292628c80 Fix ExplicitLineBreak parsing
fuzzed index out of range and moved range check into for condition as \\
followed by spaces at the end of the inline text should not be turned into an
ExplicitLineBreak (just like \\ not followed by spaces).
2019-10-29 01:03:10 +01:00
Niklas Fasching
76b157b8ce Add support for latex fragments 2019-09-28 15:04:04 +02:00
Niklas Fasching
a7563ce461 Add support for anonymous footnote definitions 2019-07-07 10:01:43 +02:00
Niklas Fasching
6dc04b4b02 Refactor footnote handling
- Remove unused footnote section title option
- Move away from maintaining a list of footnotes in the document (only needed
  for html export, potential maintainance overhead when modifying the document)
  and rather only build it on export when required.
- HTML export: Rename all footnotes to numbers (so we can support anonymous
  footnote references by assigning them a number) and export footnotes in order
  of reference, not definition. The implementation of this makes it natural to
  also stop exporting unused footnote definitions so we do that as well.
2019-07-07 10:01:43 +02:00
Niklas Fasching
da99094e20 Fix explicit line break parsing
It's possible for the input to end right after the explicit line break,
i.e. after the second \. This currently leads to an out of range index into
input (as the for loop starts with start+2 and [start:start+1] is the \\).
2019-01-12 20:08:17 +01:00
Niklas Fasching
63fef04fb3 Add support for timestamps 2019-01-06 21:01:47 +01:00
Niklas Fasching
bd33e8885e Add String() method to Node interface
Being able to very easily get the original [1] Org mode content seems like
something that will come up quite often and is very little code.

[1] it's not really the original content, but rather the pretty printed version
of that - as the semantics don't change it shouldn't matter.
2019-01-06 20:50:02 +01:00
Niklas Fasching
eb7db9b968 Improve footnote handling
- Footnotes separator rather than headline to get around i18n
- Warn on footnote redefinition
- Do not export footnote definitions at point of definition, only in the
  footnote section.
- Do not automatically exclude Footnotes section to get around possibly hiding
  other content of such a section - and i18n.
  The user has the choice of explicitly hiding the section via a :noexport:
  tag.

and some other refactoring
2018-12-26 15:42:12 +01:00
Niklas Fasching
bc9c496f97 Misc cleanup: SETUP_FILE -> SETUPFILE, empty example lines, ... 2018-12-20 15:43:16 +01:00
Niklas Fasching
d1054063cf Anchor inline regexps and improve sub/super-script
The regexps are meant to extract a match immediately following the cursor - the
anchor should have been there from the beginning...

Also empty sub/superscript doesn't make sense - nested sub/superscript does
make sense but yagni.
2018-12-20 15:43:16 +01:00
Niklas Fasching
36436a4c59 Fix inline parser unanchored regexps
fuzzed
2018-12-20 15:43:02 +01:00
Niklas Fasching
ec895cbe83 Fix headline tags, table pretty printing and multiline links
- we can't just look at the len of the string (~ #bytes) - that breaks down for
  tables containing characters consisting of multiple bytes. This handles
  more (still not all) cases and is good enough for now
- add _ to allowed tag chars - also require space between headline and tags
- links (link itself, not the description) spanning multiple lines are not
  supported - otherwise we would have to take care of splitting link and adding
  indentation for org pretty printing - and that sounds like such an edge case
  that it seems cleaner to forbid them
2018-12-19 13:15:31 +01:00
Niklas Fasching
fb837e04af Fix parsing of regular links enclosed in [] 2018-12-19 12:24:02 +01:00
Niklas Fasching
a60f844e38 Add basic support for statistic tokens (e.g. [100%] [1/1])
Org mode does not care where those tokens are when it comes to the
export (afaict). We'll do the same.

(They should only be in the first line of a list item or a headline)
2018-12-18 14:14:08 +01:00
Niklas Fasching
0eb3baf1bb Improve handling of elements containing raw text
While adding another test case from the goorgeous issues it became clear that
inline markup and html entity replacement were erronously applied to raw text
elements like inline code =foo=, src/example/export blocks, example lines,
etc.

To correctly handle those cases in both org and html exports a new
parseRawInline method had to be added.

Also some misc html export whitespace fixes and stuff
2018-12-17 13:40:15 +01:00
Niklas Fasching
ced166dc18 Fix inline parseLineBreak: Handle end of input 2018-12-17 01:38:46 +01:00
Niklas Fasching
6637e63892 Fix multiline emphasis
I didn't have a test case for this and broke it when i introduced Line nodes to
support printing back to org mode. Oops
2018-12-10 17:53:12 +01:00
Niklas Fasching
2399fec2eb Refactor RegularLink image & video handling 2018-12-03 16:59:39 +01:00
Niklas Fasching
f17923047b Refactor RegularLink: Do not fake description if none is given
To more faithfully handle inline images we need to know whether the original
link included a description - being more explicit about that will make it
easier.

see org.el/org-display-inline-images

> An inline image is a link which follows either of these
> conventions:
>
>   1. Its path is a file with an extension matching return value
>      from `image-file-name-regexp' and it has no contents.
>
>   2. Its description consists in a single link of the previous
>      type.
2018-12-03 16:59:01 +01:00
Niklas Fasching
d5665fb21c Fix footnotes starting with empty line 2018-12-03 00:35:12 +01:00
Niklas Fasching
3c2e9ed204 Add option to disable AutoLink parsing 2018-12-02 23:53:31 +01:00
Niklas Fasching
0df8bc541b Fix inline footnote definition parsing
footnote definition descriptions are always elements - not just raw inline
markup. we'll just wrap the description in a paragraph
2018-12-02 23:28:01 +01:00
Niklas Fasching
d5bf4317b2 Fix footnote ordering and some other bugs 2018-12-02 20:09:40 +01:00
Niklas Fasching
d2d9dc0fc8 Add auto links: Try to render unmarked urls as links 2018-12-02 18:37:55 +01:00
Niklas Fasching
a570fc736f Add lossless inline-definition-footnote rendering for the OrgWriter 2018-12-02 18:37:55 +01:00
Niklas Fasching
fc982125c9 Restructure directory layout: org subpackage 2018-12-02 18:37:55 +01:00
Renamed from inline.go (Browse further)