#!/usr/bin/perl use v5.36; use strict; use utf8; =head1 NAME hedgedoc2quarto - convert HedgeDoc content to Quarto =head1 VERSION Version 0.0.1 =head1 SYNOPSIS hedgedoc2quarto INFILE OUTFILE hedgedoc2quarto < INFILE > OUTFILE =head1 DESCRIPTION B reformats text content from HedgeDoc- to Quarto-flavored Markdown, and adapts embedded diagram code. Both HedgeDoc and Quarto uses Markdown, but different flavors, and whereas both handle (different subsets of) Mermaid diagrams, Quarto also (through plugins) handles PlantUML diagrams. =cut # slurp INFILE if passed as first argument, or else STDIN my ( $infile, $outfile, $bogus ) = @ARGV; die 'Too many arguments: expected INFILE and OUTFILE' if $bogus; @ARGV = ($infile) if $infile; my $content = do { local $/ = undef; <> }; # TODO: integrate with subroutine handler below $content =~ s/^ (?'fence'[``~]{3,})\s* \Kgraphviz\n (?'code'.*?\n) \k'fence' $/{dot}\n\/\/| fig-width: 100\%\n$+{code}$+{fence}/gsmx; $content =~ s/^ (?'fence'[``~]{3,})\s* \Kmermaid\n (?'type'gantt)\n (?'code'.*?\n) \k'fence' $/ # FIXME: implement option to choose output diagram language # "{mermaid}\n\%\%| fig-width: 100\%\n" # . &mmd2mmd( $+{type}, $+{code} ) "{.plantuml}\n\%\%| fig-width: 100\%\n" . &mmd2puml( $+{type}, $+{code} ) . $+{fence} /gsmex; if ($outfile) { open( FH, '>', $outfile ) or die $!; print FH $content; } else { print $content; } sub mmd2mmd ( $type, $code ) { # strip special comment marker '%%QUARTO%%' $code =~ s/^\s*+\K%%QUARTO%%//gm; return "$type\n$code"; } sub mmd2puml ( $type, $code ) { my @newcode; # strip special comment marker '%%QUARTO%%' $code =~ s/^\s*+\K%%QUARTO%%//gm; open my $fh, '<', \$code or die $!; while (<$fh>) { /^\s*+$/ and push @newcode, '' and next; /^(\s*+)%%PLANTUML%%\K.*/ and push @newcode, "$1$&" and next; # convert comments markers /^(\s*+)(?:[%]{2,}(?'comment'\s*+))?+\K.*/; my $indent = defined( $+{comment} ) ? "$1'$2" : $1; $_ = $&; /^title\s/i and push @newcode, "${indent}$_" and next; /^excludes\s+weekends\b/i and push @newcode, "${indent}saturday are closed" and push @newcode, "${indent}sunday are closed" and next; /^weekday\s+\K(?:mon|tues|wednes|thurs|fri|satur|sun)day\b/i and push @newcode, "${indent}weeks start on $&" and next; /^(?:date|axis)Format\s/i and push @newcode, "${indent}'UNSUPPORTED: $_" and next; /^todayMarker\s+(off|on)\b/i and push @newcode, "${indent}'UNSUPPORTED' $_" and next; /^section\s+\K\S+(?:\s+\S+)*/i and push @newcode, "${indent}-- $& --" and next; if (/^tickInterval\s+(?'tickAmount'\d+)(?'tickUnit'millisecond|second|minute|hour|day|week|month)\s*$/i ) { push @newcode, "${indent}projectscale daily" and next if $+{tickAmount} eq 1 and $+{tickUnit} eq 'day'; push @newcode, "${indent}projectscale weekly" and next if $+{tickAmount} eq 1 and $+{tickUnit} eq 'week'
  1. SSH_HOST = www-ruc@xayide.jones.dk
  2. SSH_BASE_PATH = public_websites/thoughtroam.abcde.../
  3. BASE_SSH = $(SSH_HOST):$(SSH_BASE_PATH)
  4. BASE_IRI = https://thoughtroam.abcdefghijklmnopqrstuvxyzæøå.dk/
  5. BASE_URI = https://thoughtroam.xn--abcdefghijklmnopqrstuvxyz-0fc0a81c.dk/
  6. PAD_ARTICLES = worlding
  7. ARTICLES = waste worlding
  8. ONTOLOGIES = learn waste
  9. ONTOLOGIES_VERSION = 0.1
  10. GRAPHS = $(patsubst ex/%.ttl,%,$(wildcard ex/*.ttl))
  11. PERL_FILES = bin/biblatex-tidy bin/hedgedoc2quarto bin/xmp2rdfxml
  12. TIDY_MARKDOWN = worlding
  13. export HEDGEDOC_COOKIES_FILE = $(CURDIR)/cookies.txt
  14. export HEDGEDOC_SERVER = https://pad.degrowth.net/
  15. all: preview
  16. preview:
  17. quarto preview
  18. render:
  19. quarto render
  20. publish:
  21. rsync -avH --delete-after _site/ $(BASE_SSH)
  22. prepare: $(patsubst %,learn/$(ONTOLOGIES_VERSION)/%.ttl,core tentacular)
  23. learn/$(ONTOLOGIES_VERSION)/%.ttl: learn/%.ttl
  24. mkdir --parents learn/0.1
  25. perl -p \
  26. -e 's,\b$(subst tentacular,learn10tac,$(subst core,learn,$*)):,:,g;' \
  27. -e 's,\Q$(BASE_URI)stub/foaf#,http://xmlns.com/foaf/0.1/,g;' \
  28. -e 's,\Q$(BASE_URI)stub/doap#,http://usefulinc.com/ns/doap#,g;' \
  29. -e 's,purl\.org/learn/\K(?=[^\d]),$(ONTOLOGIES_VERSION)/,g;' \
  30. < $< > $@
  31. cal-all: cal-fetch cal-render cal-publish
  32. cal-fetch:
  33. bin/cal-fetch.sh
  34. cal-render:
  35. bin/cal-publish.sh
  36. cal-publish:
  37. ssh $(SSH_HOST) mkdir -p $(SSH_BASE_PATH)events/
  38. rsync -avH --delete-after $(patsubst %,events/%,$(ARTICLES) superteam) $(BASE_SSH)events/
  39. pad-login:
  40. hedgedoc login --email
  41. pad-list:
  42. hedgedoc history
  43. pad-export-all: $(PAD_ARTICLES:%=pad-export-%)
  44. pad-export-worlding: ref.bib worlding/index.qmd \
  45. $(patsubst %,worlding/_%.qmd,baggrund teori_og_metode undersøgelser konklusion perspektivering kilder planer)
  46. ref.bib:
  47. hedgedoc export --md 8krqOrqnR0iAIExDTtTrxw $@
  48. perl -g -e 's/\s*\z/\n/' $@
  49. worlding/index.qmd:
  50. hedgedoc export --md MJei_2e-SjahCtmRT-xiPw $@
  51. perl -g -e 's/\s*\z/\n/' $@
  52. worlding/_baggrund.qmd:
  53. hedgedoc export --md mGHhKvXyQ5SVeTIU11isQQ $@
  54. perl -g -e 's/\s*\z/\n/' $@
  55. worlding/_teori_og_metode.qmd:
  56. hedgedoc export --md 5AbKoR-mTOij6TsCMFFDRw $@
  57. perl -g -e 's/\s*\z/\n/' $@
  58. worlding/_undersøgelser.qmd:
  59. hedgedoc export --md 5XR69V5rSEm9LwsLNtSXcQ $@
  60. perl -g -e 's/\s*\z/\n/' $@
  61. worlding/_konklusion.qmd:
  62. hedgedoc export --md ofRbx2f4QcWLR-o_kqTNCQ $@
  63. perl -g -e 's/\s*\z/\n/' $@
  64. worlding/_perspektivering.qmd:
  65. hedgedoc export --md lU8aUxCkR5GNrP-8frklFA $@
  66. perl -g -e 's/\s*\z/\n/' $@
  67. worlding/_kilder.qmd:
  68. hedgedoc export --md Jt6S4tAhQM-BUrAP-OllCg $@
  69. perl -g -e 's/\s*\z/\n/' $@
  70. worlding/_planer.qmd:
  71. hedgedoc export --md qfFl3xiaQWCbpoyNPbNsEA $@~
  72. bin/hedgedoc2quarto $@~ $@
  73. $(PAD_ARTICLES:%=pad-import-%): pad-import-%:
  74. hedgedoc import $*/index.qmd
  75. pad-import-ref:
  76. hedgedoc import ref.bib
  77. lint: lint-markdown
  78. lint-markdown:
  79. @mdl --ignore-front-matter --style .mdl.rb $(filter-out %/index.qmd,$(wildcard $(addsuffix /*.qmd,$(TIDY_MARKDOWN))))
  80. tidy: tidy-bibtex tidy-perl
  81. tidy-bibtex: ref.bib
  82. bin/biblatex-tidy $<
  83. tidy-perl:
  84. perltidy -b -bext='/' --profile=.perltidyrc $(PERL_FILES)
  85. $(ARTICLES:%=screening-of-%): screening-of-%:
  86. QUARTO_LOG_LEVEL=quiet \
  87. quarto render $*/index.qmd --to man --output - | man -l -
  88. $(ARTICLES:%=wordcount-of-%): wordcount-of-%:
  89. QUARTO_LOG_LEVEL=quiet \
  90. quarto render $*/index.qmd --to plain --columns=9999 --output - \
  91. | perl -nE 'next if /^-*$$/; $$bilag += $$_ =~ "^Bilag\\b"; $$chars += length unless $$bilag; END { say $$chars }'
  92. $(ARTICLES:%=turtle-from-%): turtle-from-%:
  93. @bin/xmp2rdfxml _site/$*/S*.pdf \
  94. | rapper -i rdfxml -o turtle - $(BASE_IRI)$*/
  95. $(ARTICLES:%=dotgraph-from-%): dotgraph-from-%:
  96. @bin/xmp2rdfxml _site/$*/S*.pdf \
  97. | rapper -i rdfxml -o dot - $(BASE_IRI)$*/
  98. diff-all: $(ARTICLES:%=diff-of-%)
  99. $(ARTICLES:%=diff-of-%): diff-of-%: %/changes.tex
  100. $(ARTICLES:%=%/changes.tex): %/changes.tex: %/a.tex %/b.tex
  101. latexdiff --type CULINECHBAR --subtype COLOR --replace-context2cmd '' $^ > $*/changes.tex
  102. perl -i -pe 's/\[pdftex\]{changebar}/[luatex]{changebar}/g' $*/changes.tex
  103. latexmk --gg --lualatex --cd --silent --Werror $*/changes.tex
  104. find $*/ -name 'changes.*' -not -name changes.pdf -delete
  105. rm -f $^
  106. $(ARTICLES:%=%/a.tex): %/a.tex:
  107. git switch --detach $(shell git describe --tags --abbrev=0)
  108. QUARTO_LOG_LEVEL=quiet \
  109. quarto render $*/index.qmd --to pdf -M keep-tex:true --output a.pdf
  110. mv --force $*/index.tex $@
  111. rm --force _site/a.pdf
  112. $(ARTICLES:%=%/b.tex): %/b.tex:
  113. git switch -
  114. QUARTO_LOG_LEVEL=quiet \
  115. quarto render $*/index.qmd --to pdf -M keep-tex:true --output b.pdf
  116. mv --force $*/index.tex $@
  117. rm --force _site/b.pdf
  118. %/concepts.svg: %/core.sdm
  119. sdml draw --diagram concepts -i $< -f svg -o $@
  120. %/er.svg: %/core.sdm
  121. sdml draw --diagram entity-relationship -i $< -f svg -o $@
  122. %/uml.svg: %/core.sdm
  123. sdml draw --diagram uml-class -i $< -f svg -o $@
  124. %.ttl: %.sdm
  125. sdml convert -i $< -f rdf -o $@ --no-color
  126. %/core.puml: %/core.ttl %/prefixes.ttl
  127. rdfpuml $<
  128. %/core.png: %/core.puml
  129. plantuml -tpng $<
  130. %/core.svg: %/core.puml
  131. plantuml -tsvg $<
  132. ex/%.puml: ex/%.ttl ex/prefixes.ttl
  133. rdfpuml $<
  134. ex/%.png: ex/%.puml
  135. plantuml -tpng $<
  136. ex/%.svg: ex/%.puml
  137. plantuml -tsvg $<
  138. %/docs/index.html: %/core.ttl
  139. mkdir --parents $*/docs
  140. ontospy gendocs --type 2 -x -o $(CURDIR)/$*/docs $<
  141. $(ONTOLOGIES:%=view-%-concept-diagram): view-%-concept-diagram: %/concepts.svg
  142. inkview $<
  143. $(ONTOLOGIES:%=view-%-er-diagram): view-%-er-diagram: %/er.svg
  144. inkview $<
  145. $(ONTOLOGIES:%=view-%-uml-diagram): view-%-uml-diagram: %/uml.svg
  146. inkview $<
  147. $(ONTOLOGIES:%=view-%-rdfs-graf): view-%-rdfs-graf: %/core.ttl
  148. rdfs2dot -f turtle $< | xdot -
  149. view-learn_tentacular-rdfs-graf: learn/tentacular.ttl
  150. rdfs2dot -f turtle $< | xdot -
  151. view-learn_all-rdfs-graf: learn/core.ttl learn/tentacular.ttl
  152. rdfs2dot -f turtle $^ | xdot -
  153. #$(ONTOLOGIES:%=view-%-puml-diagram): view-%-puml-diagram: %/core.svg
  154. # inkview $<
  155. $(ONTOLOGIES:%=view-%-puml-diagram): view-%-puml-diagram: %/core.png
  156. imv-wayland $<
  157. $(GRAPHS:%=view-%-puml-diagram): view-%-puml-diagram: ex/%.png
  158. imv-wayland $<
  159. $(ONTOLOGIES:%=render-%-ontology): render-%-ontology: %/docs/index.html