From add727c01192e87481c7ce0a87394ad6b9bc10fe Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Mon, 29 Jun 2020 16:48:46 +0200 Subject: [PATCH] html: Wrap headline+content & headline content in containers Org mode does it. --- org/html_writer.go | 6 +- org/testdata/footnotes.html | 8 ++ org/testdata/footnotes_in_headline.html | 2 + org/testdata/headlines.html | 36 ++++++++ org/testdata/misc.html | 116 ++++++++++++++++++++++++ org/testdata/options.html | 4 + 6 files changed, 171 insertions(+), 1 deletion(-) diff --git a/org/html_writer.go b/org/html_writer.go index 3333906..d66e6ef 100644 --- a/org/html_writer.go +++ b/org/html_writer.go @@ -249,6 +249,7 @@ func (w *HTMLWriter) WriteHeadline(h Headline) { } } + w.WriteString(fmt.Sprintf(`
`, h.ID(), h.Lvl+1) + "\n") w.WriteString(fmt.Sprintf(``, h.Lvl+1, h.ID()) + "\n") if w.document.GetOption("todo") != "nil" && h.Status != "" { w.WriteString(fmt.Sprintf(`%s`, h.Status) + "\n") @@ -267,7 +268,10 @@ func (w *HTMLWriter) WriteHeadline(h Headline) { w.WriteString(fmt.Sprintf(`%s`, strings.Join(tags, " "))) } w.WriteString(fmt.Sprintf("\n\n", h.Lvl+1)) - WriteNodes(w, h.Children...) + if content := w.WriteNodesAsString(h.Children...); content != "" { + w.WriteString(fmt.Sprintf(`
`, h.ID(), h.Lvl+1) + "\n" + content + "
\n") + } + w.WriteString("
\n") } func (w *HTMLWriter) WriteText(t Text) { diff --git a/org/testdata/footnotes.html b/org/testdata/footnotes.html index 1fb5b4b..4b6b9e4 100644 --- a/org/testdata/footnotes.html +++ b/org/testdata/footnotes.html @@ -6,9 +6,11 @@ +

Using some footnotes

+
  • normal footnote reference 1 2 3 (footnote names can be anything in the format [\w-])

    @@ -30,12 +32,18 @@ Rather, they are gathered and exported at the end of the document in the footnot

    footnotes that reference a non-existant definition are rendered but log a warning 7

+
+
+

Footnotes

+

Please note that the footnotes section is not automatically excluded from the export like in emacs. 8

this is not part of 8 anymore as there are 2 blank lines in between!

+
+

diff --git a/org/testdata/footnotes_in_headline.html b/org/testdata/footnotes_in_headline.html index 3852b83..1e69fbf 100644 --- a/org/testdata/footnotes_in_headline.html +++ b/org/testdata/footnotes_in_headline.html @@ -4,9 +4,11 @@ +

Title 1

+

diff --git a/org/testdata/headlines.html b/org/testdata/headlines.html index 9c65a4e..29b678a 100644 --- a/org/testdata/headlines.html +++ b/org/testdata/headlines.html @@ -18,9 +18,11 @@ +

Simple Headline [1/2]

+
  • checked

    @@ -34,28 +36,42 @@ not just where they are actually meant to be - even here >

    TODO [B] Headline with todo status & priority

    +
+

DONE Headline with TODO status

+

we can link to headlines that define a custom_id: #this-will-be-the-id-of-the-headline

+
+
+

[A] Headline with tags & priority   foo bar

+

Still outside the drawer

This is inside the drawer

Still outside the drawer

+
+
+

CUSTOM headline with custom status

+

it's possible to use #+SETUPFILE - in this case the setup file contains the following

@@ -65,24 +81,44 @@ headline with custom status
+
+
+

malformed property drawer

+

:PROPERTIES: not a property

:END:

+
+
+

level limit for headlines to be included in the table of contents

+

The toc option allows setting a level limit. For this file we set it to 1 - which means that the following headlines won't be included in the table of contents.

+

headline 2 not in toc

+
+

headline 3 not in toc

+
+
+
+

anoter headline 2 not in toc

+

you get the gist…

+
+
+
+
diff --git a/org/testdata/misc.html b/org/testdata/misc.html index 483fa2a..35ba018 100644 --- a/org/testdata/misc.html +++ b/org/testdata/misc.html @@ -78,18 +78,26 @@ +

issues from goorgeous (free test cases, yay!)

+
+

DONE #19: Support #+HTML

+

neato!

+
+
+

DONE #29: Support verse block

+

This is @@ -99,15 +107,23 @@ verse

or even a totally custom kind of block crazy ain't it?

+
+
+

DONE #30: Support #+SETUPFILE

+

see ./headlines.org

+
+
+

DONE #31: Support #+INCLUDE

+

Note that only src/example/export block inclusion is supported for now. There's quite a lot more to include (see the org manual for include files) but I don't have a use case for this yet and stuff like namespacing footnotes of included files @@ -198,10 +214,14 @@ deploy: +

+
+

DONE #33: Wrong output when mixing html with Org mode

+
@@ -216,14 +236,20 @@ deploy:
+
+
+

DONE #41: Support Table Of Contents

+
+

DONE #46: Support for symbols like ndash and mdash

+
  • ndash –

    @@ -241,17 +267,25 @@ deploy:

    note that —— is replaced with 2 mdashes and …. becomes ellipsis+. and so on - that's how org also does it

+
+
+

DONE #47: Consecutive code wrapped text gets joined

+

either this or that foo. either this or that foo.

+
+
+

DONE #50: LineBreaks in lists are preserved

+
  • this list item @@ -275,22 +309,34 @@ lists

    foo

  • +
+
+

DONE #68: Quote block with inline markup

+ +
+

DONE #72: Support for #+ATTR_HTML

+
Go is fine though. +
+
+

DONE #75: Not parsing nested lists correctly

+
  • bullet 1

    @@ -301,42 +347,72 @@ lists

+
+
+

DONE #77: Recognize code— as code plus dash

+
+

DONE #78: Emphasis at beginning of line

+

italics

Text italics

+
+
+

DONE #82: Crash on empty headline

+
+
+

just a space as title…

+
+
+
+
+

DONE #84: Paragraphs that are not followed by an empty line are not parsed correctly

+
+
Foo
+

Foo paragraph.

+
+
+
Bar
+

Bar paragraph

+
+
+
+
+

DONE #86: Multiple hyphens not converted to dashes

+

just like #46

  • @@ -369,15 +445,23 @@ Bar
+
+
+

DONE #87: Markup in footnotes is rendered literally

+

footnotes can contain markup - and other elements and stuff 1 2

+
+
+

DONE #92: src blocks only render in caps

+

The behaviour of Org mode <s TAB changed and it now inserts lowercased src blocks (go-org already handled this one)

  • @@ -401,18 +485,30 @@ uname -a
+
+
+
+
+

issues (wrongly) filed with hugo

+
+

#3874 exporting images in org mode

+

Hello, I'm writing hugo blogs using org-mode.

When inserting an image link like /home/amos/Pictures/Screenshots/img-2017-09-11-165647.png, hugo doesn't export the image.

+
+
+

#4006 source code blocks in org not rendered correctly

+
@@ -425,22 +521,42 @@ When inserting an image link like 
 

misc fuzz / regression / edge case

+
+

index out of range in headline priority parsing

+
+
[#B
+
+
+
+

index out of range in explicit line break parsing

+

0\\

+
+
+
+
+

Footnotes

+

diff --git a/org/testdata/options.html b/org/testdata/options.html index f003629..72e1eb6 100644 --- a/org/testdata/options.html +++ b/org/testdata/options.html @@ -1,8 +1,10 @@ +

DONE [A] #+OPTIONS: toggles supported by go-org   tag1 tag2

+

go-org supports multiple export toggles as described in the export settings section of the Org mode manual. By default (most of?) those toggles are enabled. This file starts with #+OPTIONS: toc:nil f:nil e:nil and thus disables the table of contents, footnotes & entities. @@ -45,3 +47,5 @@ As buffer options are merged with the defaults, the above headline will be expor +

+