Skip to content

Commit 6169d8d

Browse files
try fixing newlines
1 parent 6ff025f commit 6169d8d

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

pages/wiki-in-1996/fix-dot.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<pre id=result>working</pre>
2+
<script type=module>
3+
4+
// curl -s http://ward.dojo.fed.wiki/patterns-on-wiki-1996.json | jq -r '.story[]|select(.type=="graphviz")|.text' | perl -e '$_ = join("", <STDIN>);s/label="[^"]*?\n.*?"/($& =~ s/\\n/\\\n/)/g; print;'
5+
6+
const page = await fetch('http://ward.dojo.fed.wiki/patterns-on-wiki-1996.json').then(res => res.json())
7+
const item = page.story.find(item => item.type == 'graphviz')
8+
const text = item.text
9+
let openquote = false
10+
11+
window.result.innerText = text.split(/\n/).reduce(fixer,'')
12+
13+
function fixer(sum,each) {
14+
if(openquote) {
15+
if (each.match(/"/)) openquote = false
16+
return sum + "\\n" + each
17+
} else if(each.match(/\[label="[^"]*$/)) {
18+
openquote = true
19+
return sum + "\n" + each
20+
} else {
21+
return sum + "\n" + each
22+
}
23+
}
24+
25+
</script>

0 commit comments

Comments
 (0)