Commit graph

189 commits

Author SHA1 Message Date
Niklas Fasching
c1b428de28 html: Clean up and simplify code
- we can use type casting to check for type instead of adding a dependency on
  reflect
- lint complains about redundant types, so get rid of that for peace of mind
2023-03-12 11:28:55 +01:00
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
linchen2chris
29e77a0555 update the fixtures 2023-03-02 17:56:27 +08:00
linchen2chris
538fa3b3c5 make classname with priority and lowercase 2023-03-02 17:54:06 +08:00
linchen2chris
1dcadee27e make tag support other language 2023-02-21 19:10:11 +08:00
linchen2chris
acd8b842b6 make it possible to customize style for status/priority/tag 2023-02-21 18:48:17 +08:00
glacials
97d5ac5933 Allow customizing header level offset
Allows consumers to specify `TopLevelHLevel` to `HTMLWriter`, which
works identically to Org's official [`:html-toplevel-hlevel` /
`org-html-toplevel-hlevel`](https://orgmode.org/manual/Publishing-options.html) property.

Fixes #94.
2023-02-18 15:08:18 -08:00
Niklas Fasching
1849701ba7 Add support for latex blocks / environments
current support for latex fragments was inline only, i.e. lines containing block
elements (e.g. a line starting with `* `, i.e. a headline) will not be parsed
as part of the latex fragment but the respective block element. Parsing latex
blocks at the block level should fix that. Note that in any case we don't do
any processing and just emit the raw latex (leaving the rendering to e.g. js).
2022-11-02 14:16:57 +01:00
Niklas Fasching
05a2dedbf8 Remove superfluous []string declarations 2022-11-01 12:41:51 +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
xjzi
b54ef128ef Correct link to orgmode docs 2022-08-26 10:50:40 -04:00
xjzi
81cb0c3735 Don't wrap simple titles in <p>
Before this commit, if an org document was titled "Title here", the
first line of HTML output would be as follows:

<h1 class="title"><p>Title here\n</p></h1>

This commit changes the HTML writer to instead output the following:

<h1 class="title">Title Here</h1>

I conversatively modified the code, so there might be more cases where
elements should be omitted from the title.
2022-08-21 12:37:51 -04:00
Kisaragi Hiu
a7a960c460
highlight: add tests for ParseRanges 2022-07-25 19:27:11 +09:00
Kisaragi Hiu
ab8d3bc16a
highlight: support highlighting lines in the default writer
The hl_lines key is specifically the same as Hugo's key.
2022-07-18 03:56:15 +09:00
Kisaragi Hiu
9b56fc914c
highlight: Expose node params so we can pass options to Chroma 2022-07-18 03:51:04 +09:00
Niklas Fasching
a520664dc7 emphasis: Fix reading of prev/next rune for multibyte characters 2022-06-18 16:10:19 +02:00
Niklas Fasching
0f145082ad Refactor writer tests
Until now we're not using t.Run to create a sub test for each fixture - for the
current bug I want to only run a single file as I'm a print debugger and don't
care for the noise of logs from other tests. While at it, it made sense to
merge the implementations.
2022-06-18 16:10:19 +02:00
Niklas Fasching
8e11cc3db0 Fix html entities: support \<entity>{} and prevent partial replacements 2022-04-28 18:09:42 +02:00
Joseph Burnett
aff78bc23d Support fast tags by trimming the key binding. 2021-10-28 17:23:19 +02:00
Niklas Fasching
9995b3cdad html: Improve link abbreviation (#+LINK) resolution
Handle `%s`/`%h` interpolation and add support for shorthand of prefix only
links / links with empty tag (i.e. `[example]` instead of [example:]). See
[1] and [2]. As so often we don't match org mode output completely but our
output looks sane enough to me so let's move along for now.

[1] https://orgmode.org/manual/Link-Abbreviations.html
[2] https://github.com/bzg/org-mode/blob/main/lisp/ol.el#L1011
2021-10-25 16:50:15 +02:00
Niklas Fasching
34dfe32024 Document ealb in options.org fixture 2021-07-25 21:54:15 +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
Ori
4d3a099922 For simple list items, don't wrap in <p> tags
This also removes extra newlines for simple list items, see changes to
tests for details.

Closes #57
2021-07-13 23:41:32 +02:00
Niklas Fasching
abb81851be html: Hide excluded headlines from TOC
emacs org mode did it first
2021-07-13 20:54:23 +02:00
Niklas Fasching
21f1af7d48 Add support for custom numbering of ordered list using [@\d+]
org mode supports [1] setting the value attribute [2] of ordered list items to
change the numbering for the current and following items. Let's do the same. As
the attribute has no meaning for other types of lists [2] we'll just not
support it for those cases [3].

[1] https://orgmode.org/manual/Plain-Lists.html#Plain-Lists
[2] https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li#attributes
[3]
Org mode seems to instead set the id attribute for e.g. unordered lists
starting with `[@\d+]\s` - but I don't really see the value in that and will
skip that for now.
2021-04-17 15:43:19 +02:00
Niklas Fasching
b3edd6c182 Improve block parameter parsing
The actual parameter parsing logic in emacs org mode is quite complex [1]. All
we want for now is to handle parameter values containing spaces [2]. Splitting
on ` :` gets us close enough for now. As I'm very opposed to copying 100 lines
of parameter parsing logic just to get exports right let's wait for use cases -
no hurt in gathering requirements as we go.

[1] https://github.com/bzg/org-mode/blob/master/lisp/ob-core.el#L1481
[2] I never ran into such parameters before and wrongly assumed that splitting
on spaces would be enough. boy was i wrong - just look at that massive
function [1]! that's why we can't have nice things!
2021-04-11 21:52:12 +02:00
Niklas Fasching
b9f05878fa Revert "Manually install go 1.16 until github actions updates image"
This reverts commit bf7f957af2.

We still have to manually install it for now but we don't have to fuck around
with env vars anymore. github actions still defaults to go 1.15 [1]. Whatever.

[1]
```
ls -lisah $(which go)
108022 0 lrwxrwxrwx 1 root root 42 Mar 18 22:15 /usr/bin/go ->
/opt/hostedtoolcache/go/1.15.10/x64/bin/go
```
2021-03-28 17:23:05 +02:00
Niklas Fasching
7c239a7aeb html: Add support for #+TOC keyword
org mode allows rendering the toc anywhere in the html document using the `TOC`
keyword [1]. There's more options but `#+TOC: headlines $n` should be enough
for starters. Note that org mode still requires setting `#+OPTIONS: toc:nil` to
disable the default toc

[1] https://orgmode.org/manual/Table-of-Contents.html
2021-03-28 17:12:25 +02:00
Niklas Fasching
bf7f957af2 Revert Me: Manually install go 1.16 until github actions updates image 2021-03-01 14:19:14 +01:00
Niklas Fasching
5dadf8c4c2 html: Support pretty relative links
Hugo defaults to serving files with pretty urls [1] - this means
`/posts/foo.org` is served at `/posts/foo/`. This works because servers
default to serving index.html when a directory is specified and hugo renders
the post to `/posts/foo/index.html` instead of `/posts/foo.html`. To make
relative links work we need to (1) remove the fake `foo/` subdirectory from
unrooted links and (2) replace any `.org` suffix with `/`.

[1] https://gohugo.io/content-management/urls/#pretty-urls
2021-01-02 20:48:28 +01:00
Niklas Fasching
84d56e9562 html: Rewrite local links to .org files to .html
emacs rewrites links to `.org` files to corresponding links with `.html`
extension in the html export.
2021-01-02 20:47:55 +01:00
Niklas Fasching
1b68e209ac Migrate from travisci to github actions
because all my other repos use it and hackernews told me travisci free tier is
dead.
2021-01-02 20:42:59 +01:00
Perry Kundert
4cf9dff010 Add a lower-case org-mode drawer 🔚 test 2020-11-20 11:41:24 -08:00
Perry Kundert
04fec98ffd Make ORG-mode drawer "🔚" case-insensitivie 2020-11-16 12:37:37 -08:00
Niklas Fasching
c025db7bdd Fix comments: comments must start with #\s not just # 2020-07-28 19:28:30 +02:00
Niklas Fasching
64b2b22270 Fix list item parsing and headline token lvls
As headlines are always lvl (indent) 0 I thought it would be clever to abuse
the lvl field to store the headline lvl. Well, here we are - it wasn't clever.

List items only end when their parent ends or they run into something that's
not indented enough - everything else becomes part of the list item. Abusing
the token.lvl field (indent) for the headline lvl means headlines look indented
to the list item parsing logic - i.e. they become part of the list item if the
headline has a high enough lvl. That should never happen - so let's get rid of
the hack and (re-)calculate the headline lvl when we need it.
2020-07-22 13:49:58 +02:00
Niklas Fasching
add727c011 html: Wrap headline+content & headline content in containers
Org mode does it.
2020-06-29 16:48:46 +02:00
Niklas Fasching
55b149054d fuzz: Fix index out of range for results without content
Offending crasher:

"\n\n\n\n\n\n\n\n\n#+RESULTS:"
2020-06-28 21:26:55 +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
e076412b29 html: Implement fat table rows (use tbodies to represent separators)
html does not support table separator rows as Org mode does. Emacs org export
simulates rows as defined by separators by wrapping all the rows between 2
separators into a separate tbody. The html spec is fine with that [0] so we
follow.

[0] https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody
2020-06-26 20:11:14 +02:00
Niklas Fasching
5917d8fb1c Store table separator indices
We want to support fat rows in tables - for that we need to know where the
separators are.
2020-06-26 20:05:59 +02:00
Niklas Fasching
a383eef7a6 html: Remove cosmetic whitespace inside p tags
All tags are put on a line by themselves to help with visual
diffing. Apparently this extra cosmetic whitespace causes problems inside p
tags for ppl who want to use `white-space: pre`. Not much hurt for visual
diffing in removing cosmetic whitespace for just p tags and can't think of
anything that would break because of this right now. So let's do it and wait
for things to break.
2020-06-26 18:55:15 +02:00
Niklas Fasching
5e50794af0 Add title export option
see https://orgmode.org/manual/Export-Settings.html
2020-06-26 12:25:17 +02:00
Niklas Fasching
9ffcaa8e1c Add support for table column display width markers
see https://orgmode.org/manual/Column-Width-and-Alignment.html#Column-Width-and-Alignment
2020-06-21 22:13:31 +02:00
Niklas Fasching
9f7e8a8fbd Implement #+MACRO 2020-04-17 16:41:06 +02:00
Niklas Fasching
2ab65d300a Fix #+LINK: file xyz edge case
if we define a custom LINK for file we run into index problems bc it's trimmed
before already - this fixes that. Shouldn't ever happen but whatever, fuzzing
found it.
2020-04-17 16:18:33 +02:00
Niklas Fasching
1e36b3b46b Implement #+LINK 2020-04-17 15:59:03 +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
7e69931976 html: Implement source block :exports parameter 2020-04-17 15:24:42 +02:00
Niklas Fasching
efe1c4eb07 html: Cleanup block name switch 2020-04-17 15:12:04 +02:00