Merge pull request #114 from donaldh/noweb-redux

Honour org :noweb strip-export parameter when writing HTML
This commit is contained in:
Niklas Fasching 2024-05-29 19:20:39 +02:00 committed by GitHub
commit f7c2b120f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 21 additions and 2 deletions

View file

@ -241,7 +241,7 @@ func (d *Document) parseOne(i int, stop stopFn) (consumed int, node Node) {
if consumed != 0 { if consumed != 0 {
return consumed, node return consumed, node
} }
d.Log.Printf("Could not parse token %#v: Falling back to treating it as plain text.", d.tokens[i]) d.Log.Printf("Could not parse token %#v in file %s: Falling back to treating it as plain text.", d.tokens[i], d.Path)
m := plainTextRegexp.FindStringSubmatch(d.tokens[i].matches[0]) m := plainTextRegexp.FindStringSubmatch(d.tokens[i].matches[0])
d.tokens[i] = token{"text", len(m[1]), m[2], m} d.tokens[i] = token{"text", len(m[1]), m[2], m}
return d.parseOne(i, stop) return d.parseOne(i, stop)

View file

@ -152,6 +152,10 @@ func (w *HTMLWriter) WriteBlock(b Block) {
if params[":exports"] == "results" || params[":exports"] == "none" { if params[":exports"] == "results" || params[":exports"] == "none" {
break break
} }
if params[":noweb"] == "strip-export" {
stripNoweb := regexp.MustCompile(`<<[^>]+>>`)
content = stripNoweb.ReplaceAllString(content, "")
}
lang := "text" lang := "text"
if len(b.Parameters) >= 1 { if len(b.Parameters) >= 1 {
lang = strings.ToLower(b.Parameters[0]) lang = strings.ToLower(b.Parameters[0])

View file

@ -45,7 +45,7 @@ func testWriter(t *testing.T, newWriter func() Writer, ext string) {
if err != nil { if err != nil {
t.Fatalf("%s\n got error: %s", path, err) t.Fatalf("%s\n got error: %s", path, err)
} else if actual != expected { } else if actual != expected {
t.Fatalf("%s:\n%s'", path, "") t.Fatalf("%s:\n%s'", path, diff(actual, expected))
} }
}) })
} }

View file

@ -195,3 +195,10 @@ Snow covers Emacs</p>
</ul> </ul>
</li> </li>
</ul> </ul>
<div class="src src-raku">
<div class="highlight">
<pre>
describe &lt;a b c&gt;;
</pre>
</div>
</div>

View file

@ -176,3 +176,7 @@ this unindented line is outside of the list item
---AlexSchroeder ---AlexSchroeder
#+END_VERSE #+END_VERSE
#+BEGIN_SRC raku :results output :noweb strip-export :exports both
<<defn>>describe <a b c>;
#+END_SRC

View file

@ -176,3 +176,7 @@ this unindented line is outside of the list item
---AlexSchroeder ---AlexSchroeder
#+END_VERSE #+END_VERSE
#+BEGIN_SRC raku :results output :noweb strip-export :exports both
<<defn>>describe <a b c>;
#+END_SRC