From 021a906ee64667a654359c25e682cc646d63ec38 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Mon, 6 Mar 2017 17:20:36 -0500 Subject: [PATCH 01/43] Initial HTML export This exports a basic html file, with the option to specify which properties are written. Annotations and their properties are wrapped in div tags with classes specified automatically, leaving ID open for the moment. The point of id for individual annotations will obviously be to link to score items once that is eventually approached. Different annotation lists (as/in bookparts) in a book could also use id's to differentiate themselves from one another. --- annotate/config.ily | 20 ++++++++ annotate/export-html.ily | 97 ++++++++++++++++++++++++++++++++++++++ annotate/module.ily | 1 + usage-examples/annotate.ly | 2 +- 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 annotate/export-html.ily diff --git a/annotate/config.ily b/annotate/config.ily index 82a1853..7aa1b60 100644 --- a/annotate/config.ily +++ b/annotate/config.ily @@ -111,6 +111,26 @@ (question . "Question:") (todo . "TODO:")) + + +%%%%%%%%%%%%%%%%% +%%%% HTML options +%%%%%%%%%%%%%%%%% + +% Annotation types for html text output +\registerOption scholarly.annotate.export.html.labels +#`((critical-remark . "critical-remark") + (musical-issue . "musical-issue") + (lilypond-issue . "lilypond-issue>") + (question . "question") + (todo . "todo")) + +% Which props to print to html +\registerOption scholarly.annotate.export.html.props + #`(type grob-type message) + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Handling of annotation types for LaTeX output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/annotate/export-html.ily b/annotate/export-html.ily new file mode 100644 index 0000000..e044caf --- /dev/null +++ b/annotate/export-html.ily @@ -0,0 +1,97 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% This file is part of ScholarLY, % +% ========= % +% a toolkit library for scholarly work with GNU LilyPond and LaTeX, % +% belonging to openLilyLib (https://github.com/openlilylib/openlilylib % +% ----------- % +% % +% ScholarLY is free software: you can redistribute it and/or modify % +% it under the terms of the GNU General Public License as published by % +% the Free Software Foundation, either version 3 of the License, or % +% (at your option) any later version. % +% % +% ScholarLY is distributed in the hope that it will be useful, % +% but WITHOUT ANY WARRANTY; without even the implied warranty of % +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % +% GNU Lesser General Public License for more details. % +% % +% You should have received a copy of the GNU General Public License % +% along with ScholarLY. If not, see . % +% % +% ScholarLY is maintained by Urs Liska, ul@openlilylib.org % +% Copyright Urs Liska, 2015-17 % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Export annotations to html file +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +#(define (nest-indent inpt num) + (let* ((indentation "")) + (do ((i 0 (1+ i))) + ((= i num)) + (set! indentation (string-append indentation " "))) + (string-append indentation inpt))) + +% Probably a more sophisticated approach would be to use a list of div-props +% which contain the class (still automatically set here) as well as id's which +% may be set by the user or also automatically by scholarly. Those will presumably +% be necessary for linking the annotations to grobs later, which is an important +% feature to keep in mind. + +#(define (div-class-open name nest-level) + (let* ((class-name (string-append "
"))) + (div-begin (nest-indent class-name nest-level))) + (append-to-output-stringlist div-begin))) + +#(define (div-class-close nest-level) + (append-to-output-stringlist (nest-indent "
" nest-level))) + + +#(define (html-process-props ann) + (let ((props (getOption `(scholarly annotate export html props)))) + (if (> (length props) 0) + (do ((i 0 (1+ i))) + ((= i (length props))) + (let* ((prop (list-ref props i)) + (val (assq-ref ann prop))) + (begin + (if (symbol? val) + (set! val (symbol->string val))) + (div-class-open (symbol->string prop) 3) + (append-to-output-stringlist + (nest-indent val 4)) + (div-class-close 3))))))) + + +\register-export-routine html +#(lambda () + ;; wrap everything in the annotations div. this is sort of redundant, but + ;; could be useful if projects have multiple bookparts with annotation lists. + (div-class-open "annotations" 0) + (append-to-output-stringlist " ") + (for-each + (lambda (ann) + ;; wrap each annotation in the common annotation class + (div-class-open "annotation" 1) + ;; type as a class - maybe we want different types to have some different styles + (div-class-open + (getChildOption '(scholarly annotate export html labels) (assq-ref ann 'type)) + 2) + ;; location + (div-class-open "location" 3) + (append-to-output-stringlist (nest-indent (format-location ann) 4)) + (div-class-close 3) + ;; add the rest of the props to output + (html-process-props ann) + (div-class-close 2) + (div-class-close 1) + (append-to-output-stringlist " ")) + annotations) + ;; close ann list div + (div-class-close 0) + ;; write to output file + (write-output-file "html")) diff --git a/annotate/module.ily b/annotate/module.ily index d4bf12e..9a5141f 100644 --- a/annotate/module.ily +++ b/annotate/module.ily @@ -59,6 +59,7 @@ \include "export.ily" \include "export-latex.ily" \include "export-plaintext.ily" +\include "export-html.ily" \include "engraver.ily" % Include `editorial-functions` module diff --git a/usage-examples/annotate.ly b/usage-examples/annotate.ly index 2474020..d2ca489 100644 --- a/usage-examples/annotate.ly +++ b/usage-examples/annotate.ly @@ -8,7 +8,7 @@ \markup \vspace #1 -\setOption scholarly.annotate.export-targets #'(plaintext latex) +\setOption scholarly.annotate.export-targets #'(plaintext latex html) music = \relative c'{ c4 d e From 6f1d9f358ecfd8fea94a78e5b9fc12b604fe070c Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Mon, 6 Mar 2017 17:43:09 -0500 Subject: [PATCH 02/43] add output html for example --- usage-examples/annotate.annotations.html | 106 +++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 usage-examples/annotate.annotations.html diff --git a/usage-examples/annotate.annotations.html b/usage-examples/annotate.annotations.html new file mode 100644 index 0000000..fb90350 --- /dev/null +++ b/usage-examples/annotate.annotations.html @@ -0,0 +1,106 @@ +
+ +
+
+
+ Measure 1, beat 4 +
+
+ critical-remark +
+
+ NoteHead +
+
+ Go to \textit{school} and \textcolor{red}{sit back}! This + is a second sentence, which\fnblue has a footnote. +
+
+
+ +
+
+
+ Measure 3, beat 1 +
+
+ musical-issue +
+
+ KeySignature +
+
+ This is a musical issue with not footnotes. +
+
+
+ +
+
+
+ Measure 3, beat 3 +
+
+ critical-remark +
+
+ NoteHead +
+
+ An annotation for the top voice. +
+
+
+ +
+
+
+ Measure 3, beat 3 +
+
+ critical-remark +
+
+ NoteHead +
+
+ A note about the second voice. +
+
+
+ +
+
+
+ Measure 4, beat 2 +
+
+ lilypond-issue +
+
+ TrillSpanner +
+
+ A message about the trill. +
+
+
+ +
+
+
+ Measure 5, beat 2 +
+
+ question +
+
+ Slur +
+
+ A question with a footnote\fnRandom about the slur. +
+
+
+ +
From 07d8e2e2fcca5767a1d69a98d97b91d7bfbad5a8 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Tue, 7 Mar 2017 14:23:00 -0500 Subject: [PATCH 03/43] WIP adds some special config options for html and css --- annotate/config.ily | 4 ++++ annotate/export-html.ily | 21 +++++++++++++++++++-- annotate/export.ily | 5 ++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/annotate/config.ily b/annotate/config.ily index 7aa1b60..ffbffc9 100644 --- a/annotate/config.ily +++ b/annotate/config.ily @@ -129,6 +129,10 @@ \registerOption scholarly.annotate.export.html.props #`(type grob-type message) +% Which stylesheet to link in html (just a proof of concept at the moment) +\registerOption scholarly.annotate.export.html.css + #"annotate-styles.css" + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/annotate/export-html.ily b/annotate/export-html.ily index e044caf..0902647 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -69,9 +69,22 @@ \register-export-routine html #(lambda () + + (append-to-output-stringlist "") + (append-to-output-stringlist (string-append + " "))) + + (append-to-output-stringlist "") + (append-to-output-stringlist " ") + + (append-to-output-stringlist "") + (append-to-output-stringlist " ") + ;; wrap everything in the annotations div. this is sort of redundant, but ;; could be useful if projects have multiple bookparts with annotation lists. - (div-class-open "annotations" 0) + (append-to-output-stringlist "") (append-to-output-stringlist " ") (for-each (lambda (ann) @@ -92,6 +105,10 @@ (append-to-output-stringlist " ")) annotations) ;; close ann list div - (div-class-close 0) + (append-to-output-stringlist "") + + (append-to-output-stringlist " ") + (append-to-output-stringlist "") + ;; write to output file (write-output-file "html")) diff --git a/annotate/export.ily b/annotate/export.ily index 60b2286..96b3f99 100644 --- a/annotate/export.ily +++ b/annotate/export.ily @@ -94,7 +94,8 @@ setAnnotationOutputBasename = ; TODO ; Make the file name configurable and let it respect the target format ; - (let* ((logfile (format "~a.annotations.~a" annotation-out-basename ext))) + (let* ((logfile (if (equal? ext "html") "index.html" + (format "~a.annotations.~a" annotation-out-basename ext)))) (ly:message "writing '~a' ..." logfile) (with-output-to-file logfile (lambda () @@ -140,5 +141,3 @@ setAnnotationOutputBasename = ly:message) (ly:message ""))) annotations)) - - From 8ad731b546764c11be3dd057ca7677366d9faf47 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Tue, 7 Mar 2017 14:30:22 -0500 Subject: [PATCH 04/43] html and css example --- usage-examples/annotate-styles.css | 16 ++++++++++++++++ .../{annotate.annotations.html => index.html} | 12 ++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 usage-examples/annotate-styles.css rename usage-examples/{annotate.annotations.html => index.html} (94%) diff --git a/usage-examples/annotate-styles.css b/usage-examples/annotate-styles.css new file mode 100644 index 0000000..e30261c --- /dev/null +++ b/usage-examples/annotate-styles.css @@ -0,0 +1,16 @@ + +html, +body { + background: gray; + margin: 0.5em; +} + +annotations { + width: 100%; + height: 100%; +} + +.annotation { + margin: 1em; + background: lightgray; +} diff --git a/usage-examples/annotate.annotations.html b/usage-examples/index.html similarity index 94% rename from usage-examples/annotate.annotations.html rename to usage-examples/index.html index fb90350..10c7a82 100644 --- a/usage-examples/annotate.annotations.html +++ b/usage-examples/index.html @@ -1,4 +1,10 @@ -
+ + + + + + +
@@ -103,4 +109,6 @@
-
+ + + From 90e0eb9288599c7d19a51e97af59e81e34a476d8 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Tue, 7 Mar 2017 15:04:23 -0500 Subject: [PATCH 05/43] implements format-location and removes default props to print (user must specific any/all) --- annotate/config.ily | 2 +- annotate/export-html.ily | 39 +++++++++++++++++++-------------------- usage-examples/index.html | 36 ++++++++++++++++++------------------ 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/annotate/config.ily b/annotate/config.ily index ffbffc9..86cf42d 100644 --- a/annotate/config.ily +++ b/annotate/config.ily @@ -127,7 +127,7 @@ % Which props to print to html \registerOption scholarly.annotate.export.html.props - #`(type grob-type message) + #`(type grob-location grob-type message) % Which stylesheet to link in html (just a proof of concept at the moment) \registerOption scholarly.annotate.export.html.css diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 0902647..23e73c2 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -57,7 +57,9 @@ (do ((i 0 (1+ i))) ((= i (length props))) (let* ((prop (list-ref props i)) - (val (assq-ref ann prop))) + (val (if (equal? prop 'grob-location) + (format-location ann) + (assq-ref ann prop)))) (begin (if (symbol? val) (set! val (symbol->string val))) @@ -70,22 +72,23 @@ \register-export-routine html #(lambda () - (append-to-output-stringlist "") - (append-to-output-stringlist (string-append + (let ((println append-to-output-stringlist)) + + (println "") + (println (string-append " "))) + (println "") + (println " ") - (append-to-output-stringlist "") - (append-to-output-stringlist " ") - - (append-to-output-stringlist "") - (append-to-output-stringlist " ") + (println "") + (println " ") ;; wrap everything in the annotations div. this is sort of redundant, but ;; could be useful if projects have multiple bookparts with annotation lists. - (append-to-output-stringlist "") - (append-to-output-stringlist " ") + (println "") + (println " ") (for-each (lambda (ann) ;; wrap each annotation in the common annotation class @@ -94,21 +97,17 @@ (div-class-open (getChildOption '(scholarly annotate export html labels) (assq-ref ann 'type)) 2) - ;; location - (div-class-open "location" 3) - (append-to-output-stringlist (nest-indent (format-location ann) 4)) - (div-class-close 3) ;; add the rest of the props to output - (html-process-props ann) + (html-process-props ann) ;; nest-indents x 3 (div-class-close 2) (div-class-close 1) - (append-to-output-stringlist " ")) + (println " ")) annotations) ;; close ann list div - (append-to-output-stringlist "") + (println "") - (append-to-output-stringlist " ") - (append-to-output-stringlist "") + (println " ") + (println "") ;; write to output file - (write-output-file "html")) + (write-output-file "html"))) diff --git a/usage-examples/index.html b/usage-examples/index.html index 10c7a82..f74b375 100644 --- a/usage-examples/index.html +++ b/usage-examples/index.html @@ -8,12 +8,12 @@
-
- Measure 1, beat 4 -
critical-remark
+
+ Measure 1, beat 4 +
NoteHead
@@ -26,12 +26,12 @@
-
- Measure 3, beat 1 -
musical-issue
+
+ Measure 3, beat 1 +
KeySignature
@@ -43,12 +43,12 @@
-
- Measure 3, beat 3 -
critical-remark
+
+ Measure 3, beat 3 +
NoteHead
@@ -60,12 +60,12 @@
-
- Measure 3, beat 3 -
critical-remark
+
+ Measure 3, beat 3 +
NoteHead
@@ -77,12 +77,12 @@
-
- Measure 4, beat 2 -
lilypond-issue
+
+ Measure 4, beat 2 +
TrillSpanner
@@ -94,12 +94,12 @@
-
- Measure 5, beat 2 -
question
+
+ Measure 5, beat 2 +
Slur
From 609f89b1e4b447f925acf5c10ecd0e2f1ad504f8 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Tue, 7 Mar 2017 18:05:08 -0500 Subject: [PATCH 06/43] make export procedure / filenames configurable with options --- annotate/config.ily | 19 +++++++++++++++++++ annotate/export-html.ily | 6 +++--- annotate/export-latex.ily | 3 +-- annotate/export-plaintext.ily | 3 +-- annotate/export.ily | 18 ++++++++++++------ 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/annotate/config.ily b/annotate/config.ily index 86cf42d..6656336 100644 --- a/annotate/config.ily +++ b/annotate/config.ily @@ -94,6 +94,25 @@ \registerOption scholarly.colorize ##t + + +%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Filenames to Export +%%%%%%%%%%%%%%%%%%%%%%%% +% default is .annotations. +\registerOption scholarly.annotate.export.filenames +% +#`((html . "index.html") ;; html + (latex . default) ;; latex + (scheme . default) ;; scheme + (plaintext . default) ;; plaintext + ) + + + + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Handling of annotation types for plain text output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 23e73c2..4ce0e01 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -87,7 +87,7 @@ ;; wrap everything in the annotations div. this is sort of redundant, but ;; could be useful if projects have multiple bookparts with annotation lists. - (println "") + (div-class-open "annotations" 0) (println " ") (for-each (lambda (ann) @@ -104,10 +104,10 @@ (println " ")) annotations) ;; close ann list div - (println "") + (div-class-close 0) (println " ") (println "") ;; write to output file - (write-output-file "html"))) + (write-output-file 'html))) diff --git a/annotate/export-latex.ily b/annotate/export-latex.ily index aa2cd54..d6efd4b 100644 --- a/annotate/export-latex.ily +++ b/annotate/export-latex.ily @@ -218,5 +218,4 @@ annotations) ;; write to output file - (write-output-file "inp")) - + (write-output-file 'latex)) diff --git a/annotate/export-plaintext.ily b/annotate/export-plaintext.ily index b7a5f32..cb6b69d 100644 --- a/annotate/export-plaintext.ily +++ b/annotate/export-plaintext.ily @@ -73,5 +73,4 @@ annotations) ;; write to output file - (write-output-file "log")) - + (write-output-file 'plaintext)) diff --git a/annotate/export.ily b/annotate/export.ily index 96b3f99..dfc510e 100644 --- a/annotate/export.ily +++ b/annotate/export.ily @@ -86,16 +86,22 @@ setAnnotationOutputBasename = % Take the stringlist 'annotate-export-stringlist % and write it out to a file -#(define (write-output-file ext) +#(define (write-output-file type) ; ; TODO ; remove "messages" here and directly use the global object ; - ; TODO - ; Make the file name configurable and let it respect the target format - ; - (let* ((logfile (if (equal? ext "html") "index.html" - (format "~a.annotations.~a" annotation-out-basename ext)))) + (let* ((default-exts '((html . "html") + (latex . "inp") + (scheme . "scm") + (plaintext . "log"))) + (logfile (if (equal? (getChildOption + '(scholarly annotate export filenames) type) + 'default) + (format "~a.annotations.~a" annotation-out-basename + (assoc-ref default-exts type)) + (getChildOption + '(scholarly annotate export filenames) type)))) (ly:message "writing '~a' ..." logfile) (with-output-to-file logfile (lambda () From f17cdf97d12c86e00e2c7c22a6ef0729a012a6c6 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Tue, 7 Mar 2017 18:18:22 -0500 Subject: [PATCH 07/43] make annotations a div with so named class again --- usage-examples/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usage-examples/index.html b/usage-examples/index.html index f74b375..953c0f6 100644 --- a/usage-examples/index.html +++ b/usage-examples/index.html @@ -4,7 +4,7 @@ - +
@@ -109,6 +109,6 @@
- +
From 9a4ceb8aae4ce6c2570120dbe2dde727381f368c Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Sat, 11 Mar 2017 15:50:04 -0500 Subject: [PATCH 08/43] adds html-id prop check/addition for each annotation --- annotate/export-html.ily | 59 +++++++++++++++++++++++++++++++------- usage-examples/annotate.ly | 1 + usage-examples/index.html | 2 +- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 4ce0e01..d0c2eac 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -41,16 +41,35 @@ % be necessary for linking the annotations to grobs later, which is an important % feature to keep in mind. -#(define (div-class-open name nest-level) - (let* ((class-name (string-append "
"))) - (div-begin (nest-indent class-name nest-level))) +% convenience functions +#(define (stringify-html-tag tag) + (format "\"~a\"" tag)) +#(define (delimit-html-tags tags) + (format "
" tags)) + + +% the following two should be refactored into a single function that +% solely accepts the class name as a string, then automatically checks +% for the html-id tag prop (adding the ann argument to do that) +% and adds it if necessary. +#(define (div-class-open div-class nest-level) + (let* ((class (string-append "class=" (stringify-html-tag div-class))) + (div-tag (delimit-html-tags class)) + (div-begin (nest-indent div-tag nest-level))) (append-to-output-stringlist div-begin))) -#(define (div-class-close nest-level) - (append-to-output-stringlist (nest-indent "
" nest-level))) +#(define (div-class-id-open div-class div-id nest-level) + (let* ((class (string-append "class=" (stringify-html-tag div-class))) + (id (string-append " id=" (stringify-html-tag div-id))) + (div-tags (delimit-html-tags (string-append class id))) + (div-begin (nest-indent div-tags nest-level))) + (append-to-output-stringlist div-begin))) +#(define (div-close nest-level) + (append-to-output-stringlist (nest-indent "
" nest-level))) + +% TODO simplify the following to a lambda procedure? #(define (html-process-props ann) (let ((props (getOption `(scholarly annotate export html props)))) (if (> (length props) 0) @@ -66,7 +85,7 @@ (div-class-open (symbol->string prop) 3) (append-to-output-stringlist (nest-indent val 4)) - (div-class-close 3))))))) + (div-close 3))))))) \register-export-routine html @@ -92,19 +111,37 @@ (for-each (lambda (ann) ;; wrap each annotation in the common annotation class - (div-class-open "annotation" 1) + ;; add div ID tag if available + + + + ;(if (assq-ref ann 'html-id) + ; (let ((div-id (assoc-ref ann 'html-id))) + ; (div-class-open (string-append "annotation\"" + ; (string-append " id=\"" div-id)) 1)) + ; ;; no div ID, so just annotation class + ; (div-class-open "annotation" 1)) + + + (if (assq-ref ann 'html-id) + (let ((div-id (assoc-ref ann 'html-id))) + (div-class-id-open "annotation" div-id 1)) + ;; no div ID, so just annotation class + (div-class-open "annotation" 1)) + + ;; type as a class - maybe we want different types to have some different styles (div-class-open (getChildOption '(scholarly annotate export html labels) (assq-ref ann 'type)) 2) ;; add the rest of the props to output (html-process-props ann) ;; nest-indents x 3 - (div-class-close 2) - (div-class-close 1) + (div-close 2) + (div-close 1) (println " ")) annotations) ;; close ann list div - (div-class-close 0) + (div-close 0) (println " ") (println "") diff --git a/usage-examples/annotate.ly b/usage-examples/annotate.ly index d2ca489..0746207 100644 --- a/usage-examples/annotate.ly +++ b/usage-examples/annotate.ly @@ -32,6 +32,7 @@ music = \relative c'{ { \voiceOne \criticalRemark \with { message = "An annotation for the top voice." + html-id = "my-unique-id" } NoteHead cis d diff --git a/usage-examples/index.html b/usage-examples/index.html index 953c0f6..cb19787 100644 --- a/usage-examples/index.html +++ b/usage-examples/index.html @@ -41,7 +41,7 @@
-
+
critical-remark From 6cd604b8be49eef8b8cc41924d3a5b97a3570bcd Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Sat, 11 Mar 2017 16:18:07 -0500 Subject: [PATCH 09/43] simplify div-open procedure, make code more legible --- annotate/export-html.ily | 82 ++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 46 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index d0c2eac..7fecc44 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -47,25 +47,25 @@ #(define (delimit-html-tags tags) (format "
" tags)) - -% the following two should be refactored into a single function that -% solely accepts the class name as a string, then automatically checks -% for the html-id tag prop (adding the ann argument to do that) -% and adds it if necessary. -#(define (div-class-open div-class nest-level) - (let* ((class (string-append "class=" (stringify-html-tag div-class))) - (div-tag (delimit-html-tags class)) - (div-begin (nest-indent div-tag nest-level))) - (append-to-output-stringlist div-begin))) - -#(define (div-class-id-open div-class div-id nest-level) - (let* ((class (string-append "class=" (stringify-html-tag div-class))) - (id (string-append " id=" (stringify-html-tag div-id))) - (div-tags (delimit-html-tags (string-append class id))) - (div-begin (nest-indent div-tags nest-level))) - (append-to-output-stringlist div-begin))) - - +% open div with unique tags +#(define (div-open ann-or-string nest-level) + ;; if class = string, don't check for an id. otherwise it + ;; is an ann props list, so check for an id and apply if necessary + (if (string? ann-or-string) + (let* ((class (string-append "class=" (stringify-html-tag ann-or-string))) + (div-tag (delimit-html-tags class)) + (div-begin (nest-indent div-tag nest-level))) + (append-to-output-stringlist div-begin)) + (let* ((ann ann-or-string) + (class (string-append "class=" (stringify-html-tag "annotation"))) + (id (if (assq-ref ann 'html-id) + (string-append " id=" (stringify-html-tag (assoc-ref ann 'html-id))) + "")) + (div-tags (delimit-html-tags (string-append class id))) + (div-begin (nest-indent div-tags nest-level))) + (append-to-output-stringlist div-begin)))) + +% close any div #(define (div-close nest-level) (append-to-output-stringlist (nest-indent "
" nest-level))) @@ -82,7 +82,7 @@ (begin (if (symbol? val) (set! val (symbol->string val))) - (div-class-open (symbol->string prop) 3) + (div-open (symbol->string prop) 3) (append-to-output-stringlist (nest-indent val 4)) (div-close 3))))))) @@ -106,44 +106,34 @@ ;; wrap everything in the annotations div. this is sort of redundant, but ;; could be useful if projects have multiple bookparts with annotation lists. - (div-class-open "annotations" 0) + (div-open "annotations" 0) (println " ") + (for-each (lambda (ann) - ;; wrap each annotation in the common annotation class - ;; add div ID tag if available - + ;; wrap each annotation in the common annotation class + ;; add div ID tag if available + (div-open ann 1) - ;(if (assq-ref ann 'html-id) - ; (let ((div-id (assoc-ref ann 'html-id))) - ; (div-class-open (string-append "annotation\"" - ; (string-append " id=\"" div-id)) 1)) - ; ;; no div ID, so just annotation class - ; (div-class-open "annotation" 1)) + ;; type as a class - maybe we want different types to have some different styles + (div-open + (getChildOption '(scholarly annotate export html labels) (assq-ref ann 'type)) + 2) + ;; add the rest of the props to output + (html-process-props ann) ;; nest-indents x 3 + (div-close 2) - (if (assq-ref ann 'html-id) - (let ((div-id (assoc-ref ann 'html-id))) - (div-class-id-open "annotation" div-id 1)) - ;; no div ID, so just annotation class - (div-class-open "annotation" 1)) + (div-close 1) + (println " ")) - - ;; type as a class - maybe we want different types to have some different styles - (div-class-open - (getChildOption '(scholarly annotate export html labels) (assq-ref ann 'type)) - 2) - ;; add the rest of the props to output - (html-process-props ann) ;; nest-indents x 3 - (div-close 2) - (div-close 1) - (println " ")) annotations) + ;; close ann list div (div-close 0) - (println " ") + (println "") ;; write to output file From e0eaf628c7c8c675543d68e21f069a2d8ea234f1 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Sat, 11 Mar 2017 16:27:26 -0500 Subject: [PATCH 10/43] simplify procedure for getting html props --- annotate/export-html.ily | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 7fecc44..7dc5f9c 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -69,14 +69,12 @@ #(define (div-close nest-level) (append-to-output-stringlist (nest-indent "
" nest-level))) -% TODO simplify the following to a lambda procedure? +% get all the props we want exported from the option #(define (html-process-props ann) (let ((props (getOption `(scholarly annotate export html props)))) - (if (> (length props) 0) - (do ((i 0 (1+ i))) - ((= i (length props))) - (let* ((prop (list-ref props i)) - (val (if (equal? prop 'grob-location) + (for-each + (lambda (prop) + (let* ((val (if (equal? prop 'grob-location) (format-location ann) (assq-ref ann prop)))) (begin @@ -85,7 +83,9 @@ (div-open (symbol->string prop) 3) (append-to-output-stringlist (nest-indent val 4)) - (div-close 3))))))) + (div-close 3)))) + props))) + \register-export-routine html @@ -108,7 +108,7 @@ ;; could be useful if projects have multiple bookparts with annotation lists. (div-open "annotations" 0) (println " ") - + (for-each (lambda (ann) From 118e8977496e122b3cfde0d9029f8b957f0cc85d Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Sat, 11 Mar 2017 16:30:53 -0500 Subject: [PATCH 11/43] adds setOption example for testing html props, removes comment --- annotate/export-html.ily | 5 ----- usage-examples/annotate.ly | 3 +++ usage-examples/index.html | 18 ------------------ 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 7dc5f9c..f6ca007 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -35,11 +35,6 @@ (set! indentation (string-append indentation " "))) (string-append indentation inpt))) -% Probably a more sophisticated approach would be to use a list of div-props -% which contain the class (still automatically set here) as well as id's which -% may be set by the user or also automatically by scholarly. Those will presumably -% be necessary for linking the annotations to grobs later, which is an important -% feature to keep in mind. % convenience functions #(define (stringify-html-tag tag) diff --git a/usage-examples/annotate.ly b/usage-examples/annotate.ly index 0746207..2da6546 100644 --- a/usage-examples/annotate.ly +++ b/usage-examples/annotate.ly @@ -10,6 +10,9 @@ \setOption scholarly.annotate.export-targets #'(plaintext latex html) +\setOption scholarly.annotate.export.html.props + #`(type grob-type message) + music = \relative c'{ c4 d e \criticalRemark \with { diff --git a/usage-examples/index.html b/usage-examples/index.html index cb19787..f51927a 100644 --- a/usage-examples/index.html +++ b/usage-examples/index.html @@ -11,9 +11,6 @@
critical-remark
-
- Measure 1, beat 4 -
NoteHead
@@ -29,9 +26,6 @@
musical-issue
-
- Measure 3, beat 1 -
KeySignature
@@ -46,9 +40,6 @@
critical-remark
-
- Measure 3, beat 3 -
NoteHead
@@ -63,9 +54,6 @@
critical-remark
-
- Measure 3, beat 3 -
NoteHead
@@ -80,9 +68,6 @@
lilypond-issue
-
- Measure 4, beat 2 -
TrillSpanner
@@ -97,9 +82,6 @@
question
-
- Measure 5, beat 2 -
Slur
From 7c6c636e7e93534695805969947c5fc905b3380e Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Sat, 11 Mar 2017 16:41:32 -0500 Subject: [PATCH 12/43] seperate type class names vs type output labels --- annotate/config.ily | 8 ++++++++ annotate/export-html.ily | 12 ++++++++---- usage-examples/index.html | 12 ++++++------ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/annotate/config.ily b/annotate/config.ily index 6656336..ba8161c 100644 --- a/annotate/config.ily +++ b/annotate/config.ily @@ -138,6 +138,14 @@ % Annotation types for html text output \registerOption scholarly.annotate.export.html.labels +#`((critical-remark . "Critical Remark") + (musical-issue . "Musical Issue") + (lilypond-issue . "Lilypond Issue>") + (question . "Question") + (todo . "TODO")) + +% Annotation types for html text class tags +\registerOption scholarly.annotate.export.html.classes #`((critical-remark . "critical-remark") (musical-issue . "musical-issue") (lilypond-issue . "lilypond-issue>") diff --git a/annotate/export-html.ily b/annotate/export-html.ily index f6ca007..6e2c756 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -69,9 +69,13 @@ (let ((props (getOption `(scholarly annotate export html props)))) (for-each (lambda (prop) - (let* ((val (if (equal? prop 'grob-location) - (format-location ann) - (assq-ref ann prop)))) + (let* ((val (cond ((equal? prop 'grob-location) + (format-location ann)) + ((equal? prop 'type) + (getChildOption + `(scholarly annotate export html labels) + (assq-ref ann 'type))) + (else (assq-ref ann prop))))) (begin (if (symbol? val) (set! val (symbol->string val))) @@ -113,7 +117,7 @@ ;; type as a class - maybe we want different types to have some different styles (div-open - (getChildOption '(scholarly annotate export html labels) (assq-ref ann 'type)) + (getChildOption '(scholarly annotate export html classes) (assq-ref ann 'type)) 2) ;; add the rest of the props to output (html-process-props ann) ;; nest-indents x 3 diff --git a/usage-examples/index.html b/usage-examples/index.html index f51927a..fc910fa 100644 --- a/usage-examples/index.html +++ b/usage-examples/index.html @@ -9,7 +9,7 @@
- critical-remark + Critical Remark
NoteHead @@ -24,7 +24,7 @@
- musical-issue + Musical Issue
KeySignature @@ -38,7 +38,7 @@
- critical-remark + Critical Remark
NoteHead @@ -52,7 +52,7 @@
- critical-remark + Critical Remark
NoteHead @@ -66,7 +66,7 @@
- lilypond-issue + Lilypond Issue>
TrillSpanner @@ -80,7 +80,7 @@
- question + Question
Slur From b2c511f59fb2a5066af244188785b4a6a004d2a1 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Sat, 11 Mar 2017 16:48:03 -0500 Subject: [PATCH 13/43] remove option to rename type classes, it is an useless option right now --- annotate/config.ily | 7 ------- annotate/export-html.ily | 5 ++--- usage-examples/index.html | 2 +- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/annotate/config.ily b/annotate/config.ily index ba8161c..760db03 100644 --- a/annotate/config.ily +++ b/annotate/config.ily @@ -144,13 +144,6 @@ (question . "Question") (todo . "TODO")) -% Annotation types for html text class tags -\registerOption scholarly.annotate.export.html.classes -#`((critical-remark . "critical-remark") - (musical-issue . "musical-issue") - (lilypond-issue . "lilypond-issue>") - (question . "question") - (todo . "todo")) % Which props to print to html \registerOption scholarly.annotate.export.html.props diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 6e2c756..4880030 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -116,9 +116,8 @@ (div-open ann 1) ;; type as a class - maybe we want different types to have some different styles - (div-open - (getChildOption '(scholarly annotate export html classes) (assq-ref ann 'type)) - 2) + (div-open (symbol->string (assq-ref ann 'type)) 2) + ;; add the rest of the props to output (html-process-props ann) ;; nest-indents x 3 diff --git a/usage-examples/index.html b/usage-examples/index.html index fc910fa..e30d04d 100644 --- a/usage-examples/index.html +++ b/usage-examples/index.html @@ -64,7 +64,7 @@
-
+
Lilypond Issue>
From 96819a78060dc077448166ff5b1dbc38516e673e Mon Sep 17 00:00:00 2001 From: jeffery shivers Date: Sat, 11 Mar 2017 16:50:26 -0500 Subject: [PATCH 14/43] update readme to reflect html output --- annotate/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/annotate/README.md b/annotate/README.md index 0db1993..ae90201 100644 --- a/annotate/README.md +++ b/annotate/README.md @@ -12,11 +12,11 @@ annotations are printed* (see `scholarly/annotate/config.ily`). At the beginning the music document, we can tell *scholarLY* which types of documents to export: ```lilypond -\setOption scholarly.annotate.export-targets #'(plaintext latex) +\setOption scholarly.annotate.export-targets #'(plaintext html latex) ``` Those output files will automatically format annotations to be further processed by the -relevant programs. Currently, *plaintext* and *latex* are available, while other types +relevant programs. Currently, *plaintext*, *latex* and *html* are available, while other types are on the wishlist (such as *scheme* and *markdown*). ## Basic Syntax From 9db4a68a2ca20db62cc8a1d880f408e77d618e15 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Sun, 12 Mar 2017 11:46:07 -0400 Subject: [PATCH 15/43] add opt to print full doc or just annotations div --- annotate/config.ily | 5 ++++- annotate/export-html.ily | 37 +++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/annotate/config.ily b/annotate/config.ily index 760db03..ba39d21 100644 --- a/annotate/config.ily +++ b/annotate/config.ily @@ -144,6 +144,9 @@ (question . "Question") (todo . "TODO")) +% Print full document with header (including CSS link) and body, or just +% annotations div +\registerOption scholarly.annotate.export.html.full-document ##t % Which props to print to html \registerOption scholarly.annotate.export.html.props @@ -151,7 +154,7 @@ % Which stylesheet to link in html (just a proof of concept at the moment) \registerOption scholarly.annotate.export.html.css - #"annotate-styles.css" + #"styles.css" diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 4880030..d3d6615 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -90,18 +90,21 @@ \register-export-routine html #(lambda () - (let ((println append-to-output-stringlist)) - - (println "") - (println (string-append - " "))) - (println "") - (println " ") - - (println "") - (println " ") + (let ((println append-to-output-stringlist) + (full-doc (getOption `(scholarly annotate export html full-document)))) + + ;; If option is True, add the header and body + (if full-doc + (begin + (println "") + (println (string-append + " "))) + (println "") + (println " ") + (println "") + (println " "))) ;; wrap everything in the annotations div. this is sort of redundant, but ;; could be useful if projects have multiple bookparts with annotation lists. @@ -117,7 +120,7 @@ ;; type as a class - maybe we want different types to have some different styles (div-open (symbol->string (assq-ref ann 'type)) 2) - + ;; add the rest of the props to output (html-process-props ann) ;; nest-indents x 3 @@ -128,11 +131,13 @@ annotations) - ;; close ann list div + ;; close "annotations" div (div-close 0) - (println " ") - (println "") + (if full-doc + (begin + (println " ") + (println ""))) ;; write to output file (write-output-file 'html))) From 9384bf7ac1ce725e71cd774b84f40ce935886e20 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Sun, 12 Mar 2017 11:48:01 -0400 Subject: [PATCH 16/43] remove html stuff --- usage-examples/annotate-styles.css | 16 ----- usage-examples/index.html | 96 ------------------------------ 2 files changed, 112 deletions(-) delete mode 100644 usage-examples/annotate-styles.css delete mode 100644 usage-examples/index.html diff --git a/usage-examples/annotate-styles.css b/usage-examples/annotate-styles.css deleted file mode 100644 index e30261c..0000000 --- a/usage-examples/annotate-styles.css +++ /dev/null @@ -1,16 +0,0 @@ - -html, -body { - background: gray; - margin: 0.5em; -} - -annotations { - width: 100%; - height: 100%; -} - -.annotation { - margin: 1em; - background: lightgray; -} diff --git a/usage-examples/index.html b/usage-examples/index.html deleted file mode 100644 index e30d04d..0000000 --- a/usage-examples/index.html +++ /dev/null @@ -1,96 +0,0 @@ - - - - - - -
- -
-
-
- Critical Remark -
-
- NoteHead -
-
- Go to \textit{school} and \textcolor{red}{sit back}! This - is a second sentence, which\fnblue has a footnote. -
-
-
- -
-
-
- Musical Issue -
-
- KeySignature -
-
- This is a musical issue with not footnotes. -
-
-
- -
-
-
- Critical Remark -
-
- NoteHead -
-
- An annotation for the top voice. -
-
-
- -
-
-
- Critical Remark -
-
- NoteHead -
-
- A note about the second voice. -
-
-
- -
-
-
- Lilypond Issue> -
-
- TrillSpanner -
-
- A message about the trill. -
-
-
- -
-
-
- Question -
-
- Slur -
-
- A question with a footnote\fnRandom about the slur. -
-
-
- -
- - From dc73d399a957ac4975634828f26dddbc4580a170 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Sun, 12 Mar 2017 11:50:26 -0400 Subject: [PATCH 17/43] add the word 'json' to paragraph --- annotate/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/annotate/README.md b/annotate/README.md index ae90201..d70f31c 100644 --- a/annotate/README.md +++ b/annotate/README.md @@ -17,7 +17,7 @@ the music document, we can tell *scholarLY* which types of documents to export: Those output files will automatically format annotations to be further processed by the relevant programs. Currently, *plaintext*, *latex* and *html* are available, while other types -are on the wishlist (such as *scheme* and *markdown*). +are on the wishlist (such as *scheme*, *json* and *markdown*). ## Basic Syntax From 169cbc3ac22129726375c3e9974a9d177f363840 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Sun, 12 Mar 2017 12:04:24 -0400 Subject: [PATCH 18/43] add and doctype as well --- annotate/export-html.ily | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index d3d6615..f3df1af 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -96,6 +96,9 @@ ;; If option is True, add the header and body (if full-doc (begin + (println "") + (println "") + (println "") (println "") (println (string-append " "))) + (println "") + (println "") + (println ""))) ;; write to output file (write-output-file 'html))) From dfd8df2076f2793388a88c65cdab58c987682a34 Mon Sep 17 00:00:00 2001 From: Urs Liska Date: Sun, 12 Mar 2017 21:03:47 +0100 Subject: [PATCH 19/43] add utf-8 charset to html page --- annotate/export-html.ily | 1 + 1 file changed, 1 insertion(+) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index f3df1af..d869dfa 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -100,6 +100,7 @@ (println "") (println "") (println "") + (println "") (println (string-append " Date: Sun, 12 Mar 2017 21:16:04 +0100 Subject: [PATCH 20/43] Use format instead of chained string-append --- annotate/export-html.ily | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index d869dfa..91c44df 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -101,10 +101,9 @@ (println "") (println "") (println "") - (println (string-append - " "))) + (println + (format " " + (getOption `(scholarly annotate export html css)))) (println "") (println " ") (println "") From 6d48a1f1ff840de202a945d4b385d6edc4766fd6 Mon Sep 17 00:00:00 2001 From: Urs Liska Date: Sun, 12 Mar 2017 21:16:28 +0100 Subject: [PATCH 21/43] Fix indent of commit dfd8df20 (oops) --- annotate/export-html.ily | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 91c44df..1baef00 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -100,7 +100,7 @@ (println "") (println "") (println "") - (println "") + (println " ") (println (format " " (getOption `(scholarly annotate export html css)))) From 871d6e76ab531cdba5575287f4d9b4f2f0e3f69c Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Mon, 13 Mar 2017 19:17:15 -0400 Subject: [PATCH 22/43] adds a few more conenience fns for cleanliness; implements option to specific most div types - TO BE extended probably --- annotate/config.ily | 11 +++++++++ annotate/export-html.ily | 53 ++++++++++++++++++++++++++-------------- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/annotate/config.ily b/annotate/config.ily index ba39d21..a27f71a 100644 --- a/annotate/config.ily +++ b/annotate/config.ily @@ -148,6 +148,17 @@ % annotations div \registerOption scholarly.annotate.export.html.full-document ##t + +% Annotation div types (can technically be anything, since they get directly +% converted to string; so even a new type of div, or `a`, or whatever else.) +\registerOption scholarly.annotate.export.html.divs +#`((full-ann-list . ul) ;; the div containing all annotations + (each-ann-outer . li) ;; the outer shell of an annotation + (each-ann-inner . ul) ;; the inner shell of an annotation + (each-ann-props . li) ;; each prop + ) + + % Which props to print to html \registerOption scholarly.annotate.export.html.props #`(type grob-location grob-type message) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 1baef00..2130532 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -39,30 +39,44 @@ % convenience functions #(define (stringify-html-tag tag) (format "\"~a\"" tag)) -#(define (delimit-html-tags tags) - (format "
" tags)) +#(define (classify-html-tag class) + (format "class=\"~a\"" class)) +#(define (idify-html-tag id) + (format "id=\"~a\"" id)) +#(define (delimit-html-tags div-type tags) + (format "<~a ~a>" div-type tags)) % open div with unique tags -#(define (div-open ann-or-string nest-level) +#(define (div-open type ann-or-string nest-level) ;; if class = string, don't check for an id. otherwise it ;; is an ann props list, so check for an id and apply if necessary (if (string? ann-or-string) - (let* ((class (string-append "class=" (stringify-html-tag ann-or-string))) - (div-tag (delimit-html-tags class)) + (let* ((class (classify-html-tag ann-or-string)) + (div-type (symbol->string (getChildOption + `(scholarly annotate export html divs) + type))) + (div-tag (delimit-html-tags div-type class)) (div-begin (nest-indent div-tag nest-level))) (append-to-output-stringlist div-begin)) (let* ((ann ann-or-string) - (class (string-append "class=" (stringify-html-tag "annotation"))) + (class (classify-html-tag "annotation")) + (div-type (symbol->string (getChildOption + `(scholarly annotate export html divs) + type))) (id (if (assq-ref ann 'html-id) - (string-append " id=" (stringify-html-tag (assoc-ref ann 'html-id))) + (idify-html-tag (assoc-ref ann 'html-id)) "")) - (div-tags (delimit-html-tags (string-append class id))) + (div-tags (delimit-html-tags div-type (string-append class id))) (div-begin (nest-indent div-tags nest-level))) (append-to-output-stringlist div-begin)))) % close any div -#(define (div-close nest-level) - (append-to-output-stringlist (nest-indent "
" nest-level))) +#(define (div-close type nest-level) + (let ((div-type (symbol->string (getChildOption + `(scholarly annotate export html divs) + type)))) + (append-to-output-stringlist + (nest-indent (format "" div-type) nest-level)))) % get all the props we want exported from the option #(define (html-process-props ann) @@ -79,10 +93,10 @@ (begin (if (symbol? val) (set! val (symbol->string val))) - (div-open (symbol->string prop) 3) + (div-open 'each-ann-props (symbol->string prop) 3) (append-to-output-stringlist (nest-indent val 4)) - (div-close 3)))) + (div-close 'each-ann-props 3)))) props))) @@ -111,7 +125,7 @@ ;; wrap everything in the annotations div. this is sort of redundant, but ;; could be useful if projects have multiple bookparts with annotation lists. - (div-open "annotations" 0) + (div-open 'full-ann-list "annotations" 0) (println " ") (for-each @@ -119,29 +133,30 @@ ;; wrap each annotation in the common annotation class ;; add div ID tag if available - (div-open ann 1) + (div-open 'each-ann-outer ann 1) ;; type as a class - maybe we want different types to have some different styles - (div-open (symbol->string (assq-ref ann 'type)) 2) + ;; this also lets us make each *ann* a list itself if we want + (div-open 'each-ann-inner (symbol->string (assq-ref ann 'type)) 2) ;; add the rest of the props to output (html-process-props ann) ;; nest-indents x 3 - (div-close 2) + (div-close 'each-ann-inner 2) - (div-close 1) + (div-close 'each-ann-outer 1) (println " ")) annotations) ;; close "annotations" div - (div-close 0) + (div-close 'full-ann-list 0) (if full-doc (begin (println " ") (println "") - (println "") + (println " ") (println ""))) ;; write to output file From e56f927fe506a4c9d2314c845541894c7fb1b908 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Mon, 13 Mar 2017 19:30:06 -0400 Subject: [PATCH 23/43] just remove deprecated conenience fn --- annotate/export-html.ily | 2 -- 1 file changed, 2 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 2130532..3cd15bb 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -37,8 +37,6 @@ % convenience functions -#(define (stringify-html-tag tag) - (format "\"~a\"" tag)) #(define (classify-html-tag class) (format "class=\"~a\"" class)) #(define (idify-html-tag id) From 10444ed2fe1b232d5ec247c447a3957c311fa47d Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Mon, 13 Mar 2017 21:24:58 -0400 Subject: [PATCH 24/43] adds initial ability to simply print prop labels (like 'Type: ') with props --- annotate/config.ily | 34 +++++++++++++++++++++++++++++++--- annotate/export-html.ily | 9 ++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/annotate/config.ily b/annotate/config.ily index a27f71a..1d44878 100644 --- a/annotate/config.ily +++ b/annotate/config.ily @@ -163,9 +163,37 @@ \registerOption scholarly.annotate.export.html.props #`(type grob-location grob-type message) -% Which stylesheet to link in html (just a proof of concept at the moment) -\registerOption scholarly.annotate.export.html.css - #"styles.css" +% Which labels to print for props (only affect props included in previous list) +\registerOption scholarly.annotate.export.html.prop-labels + #`((type . "Type: ") + (grob-location . #f) + (grob-type . #f) + (message . #f)) + + +% Which stylesheet to link, or print in header, or generate +% if the `use-css` is set to default, it will ignore whatever is here +% and point to the default stylesheet. We happen to refer to that here +% by default anyway. But the name/location of that default styles should +% be hardcoded into export-html.ily presumably. +\registerOption scholarly.annotate.export.html.css-name + #"default-styles.css" + + +% How to handle CSS upon html export +% #f = no CSS at all +% #`header = print in header; +% #`linked = link in header +\registerOption scholarly.annotate.export.html.with-css + #`linked + + +% Which CSS to use when used at all +% #`default = handle the default CSS included in the repository +% #`generate = generate a new CSS (using the name from `css-name` option) +% #`external = +\registerOption scholarly.annotate.export.html.use-css + #`default diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 3cd15bb..158144e 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -81,7 +81,10 @@ (let ((props (getOption `(scholarly annotate export html props)))) (for-each (lambda (prop) - (let* ((val (cond ((equal? prop 'grob-location) + (let* ((key (assq-ref (getOption + `(scholarly annotate export html prop-labels)) + prop)) + (val (cond ((equal? prop 'grob-location) (format-location ann)) ((equal? prop 'type) (getChildOption @@ -93,7 +96,7 @@ (set! val (symbol->string val))) (div-open 'each-ann-props (symbol->string prop) 3) (append-to-output-stringlist - (nest-indent val 4)) + (nest-indent (if key (string-append key val) val) 4)) (div-close 'each-ann-props 3)))) props))) @@ -115,7 +118,7 @@ (println " ") (println (format " " - (getOption `(scholarly annotate export html css)))) + (getOption `(scholarly annotate export html css-name)))) (println "") (println " ") (println "") From b7db871e559b497a9ca52cf524ebbfbaaae2f1ee Mon Sep 17 00:00:00 2001 From: Urs Liska Date: Tue, 14 Mar 2017 08:57:52 +0100 Subject: [PATCH 25/43] Replace series' of println with single expressions --- annotate/export-html.ily | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 158144e..a26301c 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -110,19 +110,18 @@ ;; If option is True, add the header and body (if full-doc - (begin - (println "") - (println "") - (println "") - (println "") - (println " ") - (println - (format " " - (getOption `(scholarly annotate export html css-name)))) - (println "") - (println " ") - (println "") - (println " "))) + (println (format +" + + + + + + + + + +" (getOption `(scholarly annotate export html css-name))))) ;; wrap everything in the annotations div. this is sort of redundant, but ;; could be useful if projects have multiple bookparts with annotation lists. @@ -155,10 +154,10 @@ (if full-doc (begin - (println " ") - (println "") - (println " ") - (println ""))) + (println " + + +"))) ;; write to output file (write-output-file 'html))) From 35a7c7d7938775b2a7f06014abbb358c0e43d152 Mon Sep 17 00:00:00 2001 From: Urs Liska Date: Tue, 14 Mar 2017 09:36:12 +0100 Subject: [PATCH 26/43] Remove "println" helper function Based on the previous commit the need for a println function is greatly reduced, and also if we're going to add more functionality I'm pretty sure that "format" in combination with multline strings will be the better (and more functionally oriented) way to do it. --- annotate/export-html.ily | 69 +++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index a26301c..4080900 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -46,35 +46,37 @@ % open div with unique tags #(define (div-open type ann-or-string nest-level) - ;; if class = string, don't check for an id. otherwise it - ;; is an ann props list, so check for an id and apply if necessary - (if (string? ann-or-string) - (let* ((class (classify-html-tag ann-or-string)) - (div-type (symbol->string (getChildOption - `(scholarly annotate export html divs) - type))) - (div-tag (delimit-html-tags div-type class)) - (div-begin (nest-indent div-tag nest-level))) - (append-to-output-stringlist div-begin)) - (let* ((ann ann-or-string) - (class (classify-html-tag "annotation")) - (div-type (symbol->string (getChildOption - `(scholarly annotate export html divs) - type))) - (id (if (assq-ref ann 'html-id) - (idify-html-tag (assoc-ref ann 'html-id)) - "")) - (div-tags (delimit-html-tags div-type (string-append class id))) - (div-begin (nest-indent div-tags nest-level))) - (append-to-output-stringlist div-begin)))) + ;; if class = string, don't check for an id. otherwise it + ;; is an ann props list, so check for an id and apply if necessary + (let ((trailing-line (if (= nest-level 0) "\n" ""))) + (if (string? ann-or-string) + (let* ((class (classify-html-tag ann-or-string)) + (div-type (symbol->string (getChildOption + `(scholarly annotate export html divs) + type))) + (div-tag (delimit-html-tags div-type class)) + (div-begin (format "~a~a" (nest-indent div-tag nest-level) trailing-line))) + (append-to-output-stringlist div-begin)) + (let* ((ann ann-or-string) + (class (classify-html-tag "annotation")) + (div-type (symbol->string (getChildOption + `(scholarly annotate export html divs) + type))) + (id (if (assq-ref ann 'html-id) + (idify-html-tag (assoc-ref ann 'html-id)) + "")) + (div-tags (delimit-html-tags div-type (string-append class id))) + (div-begin (format "~a~a" (nest-indent div-tags nest-level) trailing-line))) + (append-to-output-stringlist div-begin))))) % close any div #(define (div-close type nest-level) - (let ((div-type (symbol->string (getChildOption + (let ((div-type (symbol->string (getChildOption `(scholarly annotate export html divs) - type)))) - (append-to-output-stringlist - (nest-indent (format "" div-type) nest-level)))) + type))) + (trailing-line (if (= nest-level 1) "\n" ""))) + (append-to-output-stringlist + (nest-indent (format "~a" div-type trailing-line) nest-level)))) % get all the props we want exported from the option #(define (html-process-props ann) @@ -105,13 +107,12 @@ \register-export-routine html #(lambda () - (let ((println append-to-output-stringlist) - (full-doc (getOption `(scholarly annotate export html full-document)))) + (let ((full-doc (getOption `(scholarly annotate export html full-document)))) - ;; If option is True, add the header and body - (if full-doc - (println (format -" + ;; If option is True, add the header and body + (if full-doc + (append-to-output-stringlist (format + " @@ -120,13 +121,11 @@ - " (getOption `(scholarly annotate export html css-name))))) ;; wrap everything in the annotations div. this is sort of redundant, but ;; could be useful if projects have multiple bookparts with annotation lists. (div-open 'full-ann-list "annotations" 0) - (println " ") (for-each (lambda (ann) @@ -145,7 +144,6 @@ (div-close 'each-ann-inner 2) (div-close 'each-ann-outer 1) - (println " ")) annotations) @@ -154,8 +152,7 @@ (if full-doc (begin - (println " - + (append-to-output-stringlist " "))) From 590327f6a7576f93b0350bd308b3aa05c33d4b25 Mon Sep 17 00:00:00 2001 From: Urs Liska Date: Tue, 14 Mar 2017 09:23:57 +0100 Subject: [PATCH 27/43] Adapt indentation to Frescobaldi style I'm not 100% sure if I can impose this but anything other than keeping indentation the way Frescobaldi does it seems to be a problem on the long run --- annotate/export-html.ily | 94 ++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 4080900..4e7a3ba 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -29,20 +29,20 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #(define (nest-indent inpt num) - (let* ((indentation "")) - (do ((i 0 (1+ i))) - ((= i num)) - (set! indentation (string-append indentation " "))) - (string-append indentation inpt))) + (let* ((indentation "")) + (do ((i 0 (1+ i))) + ((= i num)) + (set! indentation (string-append indentation " "))) + (string-append indentation inpt))) % convenience functions #(define (classify-html-tag class) - (format "class=\"~a\"" class)) + (format "class=\"~a\"" class)) #(define (idify-html-tag id) - (format "id=\"~a\"" id)) + (format "id=\"~a\"" id)) #(define (delimit-html-tags div-type tags) - (format "<~a ~a>" div-type tags)) + (format "<~a ~a>" div-type tags)) % open div with unique tags #(define (div-open type ann-or-string nest-level) @@ -80,27 +80,27 @@ % get all the props we want exported from the option #(define (html-process-props ann) - (let ((props (getOption `(scholarly annotate export html props)))) - (for-each - (lambda (prop) - (let* ((key (assq-ref (getOption - `(scholarly annotate export html prop-labels)) - prop)) - (val (cond ((equal? prop 'grob-location) - (format-location ann)) - ((equal? prop 'type) - (getChildOption - `(scholarly annotate export html labels) - (assq-ref ann 'type))) - (else (assq-ref ann prop))))) - (begin - (if (symbol? val) - (set! val (symbol->string val))) - (div-open 'each-ann-props (symbol->string prop) 3) - (append-to-output-stringlist - (nest-indent (if key (string-append key val) val) 4)) - (div-close 'each-ann-props 3)))) - props))) + (let ((props (getOption `(scholarly annotate export html props)))) + (for-each + (lambda (prop) + (let* ((key (assq-ref (getOption + `(scholarly annotate export html prop-labels)) + prop)) + (val (cond ((equal? prop 'grob-location) + (format-location ann)) + ((equal? prop 'type) + (getChildOption + `(scholarly annotate export html labels) + (assq-ref ann 'type))) + (else (assq-ref ann prop))))) + (begin + (if (symbol? val) + (set! val (symbol->string val))) + (div-open 'each-ann-props (symbol->string prop) 3) + (append-to-output-stringlist + (nest-indent (if key (string-append key val) val) 4)) + (div-close 'each-ann-props 3)))) + props))) @@ -123,38 +123,38 @@ " (getOption `(scholarly annotate export html css-name))))) - ;; wrap everything in the annotations div. this is sort of redundant, but - ;; could be useful if projects have multiple bookparts with annotation lists. - (div-open 'full-ann-list "annotations" 0) + ;; wrap everything in the annotations div. this is sort of redundant, but + ;; could be useful if projects have multiple bookparts with annotation lists. + (div-open 'full-ann-list "annotations" 0) - (for-each - (lambda (ann) + (for-each + (lambda (ann) - ;; wrap each annotation in the common annotation class - ;; add div ID tag if available - (div-open 'each-ann-outer ann 1) + ;; wrap each annotation in the common annotation class + ;; add div ID tag if available + (div-open 'each-ann-outer ann 1) ;; type as a class - maybe we want different types to have some different styles ;; this also lets us make each *ann* a list itself if we want (div-open 'each-ann-inner (symbol->string (assq-ref ann 'type)) 2) - ;; add the rest of the props to output - (html-process-props ann) ;; nest-indents x 3 + ;; add the rest of the props to output + (html-process-props ann) ;; nest-indents x 3 (div-close 'each-ann-inner 2) - (div-close 'each-ann-outer 1) + (div-close 'each-ann-outer 1)) - annotations) + annotations) - ;; close "annotations" div - (div-close 'full-ann-list 0) + ;; close "annotations" div + (div-close 'full-ann-list 0) - (if full-doc - (begin + (if full-doc + (begin (append-to-output-stringlist " "))) - ;; write to output file - (write-output-file 'html))) + ;; write to output file + (write-output-file 'html))) From 39bba6ef71bddbdc55d5abb72feb7bd1561a503d Mon Sep 17 00:00:00 2001 From: Urs Liska Date: Tue, 14 Mar 2017 09:28:56 +0100 Subject: [PATCH 28/43] Simpler implementation of nest-indent --- annotate/export-html.ily | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 4e7a3ba..40a2ef0 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -29,12 +29,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #(define (nest-indent inpt num) - (let* ((indentation "")) - (do ((i 0 (1+ i))) - ((= i num)) - (set! indentation (string-append indentation " "))) - (string-append indentation inpt))) - + (string-append (make-string num #\space) inpt)) % convenience functions #(define (classify-html-tag class) From ea1cb5117fbc92a8b40dd51d015e000e9dd63e9c Mon Sep 17 00:00:00 2001 From: Urs Liska Date: Tue, 14 Mar 2017 10:02:33 +0100 Subject: [PATCH 29/43] Reduce redundant code in "div-open" This approach includes the necessary conditionals in the bindings of the parameters themselves, avoiding to have to separate but nearly identical structures in the branches of the if clause. Additionally it fixes an issue when both class and id are present (where the space was missing in between). Now an arbitrary number of tags can be joined in an opening tag --- annotate/export-html.ily | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 40a2ef0..6fec250 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -36,33 +36,24 @@ (format "class=\"~a\"" class)) #(define (idify-html-tag id) (format "id=\"~a\"" id)) -#(define (delimit-html-tags div-type tags) - (format "<~a ~a>" div-type tags)) +#(define (delimit-html-tags tags) + (format "<~a>" (string-join tags " "))) % open div with unique tags #(define (div-open type ann-or-string nest-level) ;; if class = string, don't check for an id. otherwise it ;; is an ann props list, so check for an id and apply if necessary - (let ((trailing-line (if (= nest-level 0) "\n" ""))) - (if (string? ann-or-string) - (let* ((class (classify-html-tag ann-or-string)) - (div-type (symbol->string (getChildOption - `(scholarly annotate export html divs) - type))) - (div-tag (delimit-html-tags div-type class)) - (div-begin (format "~a~a" (nest-indent div-tag nest-level) trailing-line))) - (append-to-output-stringlist div-begin)) - (let* ((ann ann-or-string) - (class (classify-html-tag "annotation")) - (div-type (symbol->string (getChildOption - `(scholarly annotate export html divs) - type))) - (id (if (assq-ref ann 'html-id) - (idify-html-tag (assoc-ref ann 'html-id)) - "")) - (div-tags (delimit-html-tags div-type (string-append class id))) - (div-begin (format "~a~a" (nest-indent div-tags nest-level) trailing-line))) - (append-to-output-stringlist div-begin))))) + (let* ((trailing-line (if (= nest-level 0) "\n" "")) + (div-type (symbol->string + (getChildOption `(scholarly annotate export html divs) type))) + (class (classify-html-tag (if (string? ann-or-string) ann-or-string "annotation"))) + (id + (let ((html-id (and (not (string? ann-or-string)) + (assq-ref ann-or-string 'html-id)))) + (if html-id (idify-html-tag html-id) ""))) + (div-tags (delimit-html-tags (list div-type class id))) + (div-begin (format "~a~a" (nest-indent div-tags nest-level) trailing-line))) + (append-to-output-stringlist div-begin))) % close any div #(define (div-close type nest-level) From 9677c5f002fc91c1c4825840d88f0a7240819d79 Mon Sep 17 00:00:00 2001 From: Urs Liska Date: Tue, 14 Mar 2017 10:09:04 +0100 Subject: [PATCH 30/43] rename nest-indent to indent nest-indent somehow sounds to me like it would actively determine the current indentation level and add one to it, while actually it simply indents a given string. --- annotate/export-html.ily | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 6fec250..19086ad 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -28,7 +28,7 @@ %%%% Export annotations to html file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -#(define (nest-indent inpt num) +#(define (indent inpt num) (string-append (make-string num #\space) inpt)) % convenience functions @@ -52,7 +52,7 @@ (assq-ref ann-or-string 'html-id)))) (if html-id (idify-html-tag html-id) ""))) (div-tags (delimit-html-tags (list div-type class id))) - (div-begin (format "~a~a" (nest-indent div-tags nest-level) trailing-line))) + (div-begin (format "~a~a" (indent div-tags nest-level) trailing-line))) (append-to-output-stringlist div-begin))) % close any div @@ -62,7 +62,7 @@ type))) (trailing-line (if (= nest-level 1) "\n" ""))) (append-to-output-stringlist - (nest-indent (format "~a" div-type trailing-line) nest-level)))) + (indent (format "~a" div-type trailing-line) nest-level)))) % get all the props we want exported from the option #(define (html-process-props ann) @@ -84,7 +84,7 @@ (set! val (symbol->string val))) (div-open 'each-ann-props (symbol->string prop) 3) (append-to-output-stringlist - (nest-indent (if key (string-append key val) val) 4)) + (indent (if key (string-append key val) val) 4)) (div-close 'each-ann-props 3)))) props))) @@ -125,7 +125,7 @@ (div-open 'each-ann-inner (symbol->string (assq-ref ann 'type)) 2) ;; add the rest of the props to output - (html-process-props ann) ;; nest-indents x 3 + (html-process-props ann) ;; indents x 3 (div-close 'each-ann-inner 2) From eec17f24259abebb53b810bf0d0b8b4db9a72e08 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Tue, 14 Mar 2017 10:33:40 -0400 Subject: [PATCH 31/43] adds explicit css naming options --- annotate/config.ily | 17 ++++++++++------- annotate/export-html.ily | 8 +++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/annotate/config.ily b/annotate/config.ily index 1d44878..820b037 100644 --- a/annotate/config.ily +++ b/annotate/config.ily @@ -140,7 +140,7 @@ \registerOption scholarly.annotate.export.html.labels #`((critical-remark . "Critical Remark") (musical-issue . "Musical Issue") - (lilypond-issue . "Lilypond Issue>") + (lilypond-issue . "Lilypond Issue") (question . "Question") (todo . "TODO")) @@ -152,7 +152,7 @@ % Annotation div types (can technically be anything, since they get directly % converted to string; so even a new type of div, or `a`, or whatever else.) \registerOption scholarly.annotate.export.html.divs -#`((full-ann-list . ul) ;; the div containing all annotations +#`((full-ann-list . ol) ;; the div containing all annotations (each-ann-outer . li) ;; the outer shell of an annotation (each-ann-inner . ul) ;; the inner shell of an annotation (each-ann-props . li) ;; each prop @@ -165,7 +165,7 @@ % Which labels to print for props (only affect props included in previous list) \registerOption scholarly.annotate.export.html.prop-labels - #`((type . "Type: ") + #`((type . "Type: ") (grob-location . #f) (grob-type . #f) (message . #f)) @@ -176,8 +176,11 @@ % and point to the default stylesheet. We happen to refer to that here % by default anyway. But the name/location of that default styles should % be hardcoded into export-html.ily presumably. -\registerOption scholarly.annotate.export.html.css-name - #"default-styles.css" +\registerOption scholarly.annotate.export.html.external-css-name + #"my-external-styles.css" + +\registerOption scholarly.annotate.export.html.generate-css-name + #"my-generated-styles.css" % How to handle CSS upon html export @@ -188,10 +191,10 @@ #`linked -% Which CSS to use when used at all +% Which CSS to use when used at all (default is the fallback if not one of the other two) % #`default = handle the default CSS included in the repository % #`generate = generate a new CSS (using the name from `css-name` option) -% #`external = +% #`external = (link to) external stylesheet (does not support *importing* yet) \registerOption scholarly.annotate.export.html.use-css #`default diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 19086ad..9e6facd 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -97,6 +97,12 @@ ;; If option is True, add the header and body (if full-doc + (let* ((css-type (getOption `(scholarly annotate export html use-css))) + (css-name (cond ((equal? css-type 'generate) + (getOption `(scholarly annotate export html generate-css-name))) + ((equal? css-type 'external) + (getOption `(scholarly annotate export html external-css-name))) + (else "default-stylesheet.css")))) (append-to-output-stringlist (format " @@ -107,7 +113,7 @@ -" (getOption `(scholarly annotate export html css-name))))) +" css-name)))) ;; wrap everything in the annotations div. this is sort of redundant, but ;; could be useful if projects have multiple bookparts with annotation lists. From 654b7cde59c3ee628f55f4647142a3798cbe53b2 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Tue, 14 Mar 2017 11:43:30 -0400 Subject: [PATCH 32/43] change equal to eq and just fix indentation --- annotate/export-html.ily | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 9e6facd..67923c0 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -98,11 +98,11 @@ ;; If option is True, add the header and body (if full-doc (let* ((css-type (getOption `(scholarly annotate export html use-css))) - (css-name (cond ((equal? css-type 'generate) - (getOption `(scholarly annotate export html generate-css-name))) - ((equal? css-type 'external) - (getOption `(scholarly annotate export html external-css-name))) - (else "default-stylesheet.css")))) + (css-name (cond ((eq? css-type 'generate) + (getOption `(scholarly annotate export html generate-css-name))) + ((eq? css-type 'external) + (getOption `(scholarly annotate export html external-css-name))) + (else "default-stylesheet.css")))) (append-to-output-stringlist (format " From c9b47457fd120480508f3f9cf8abd2212b567777 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Tue, 14 Mar 2017 21:50:45 -0400 Subject: [PATCH 33/43] WIP a css formatter for exported or header (generated, or default) --- annotate/config.ily | 14 +++++++- annotate/export-html.ily | 72 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/annotate/config.ily b/annotate/config.ily index 820b037..c9188ac 100644 --- a/annotate/config.ily +++ b/annotate/config.ily @@ -186,7 +186,7 @@ % How to handle CSS upon html export % #f = no CSS at all % #`header = print in header; -% #`linked = link in header +% #`linked = link in header, which also means export css (default or generated) \registerOption scholarly.annotate.export.html.with-css #`linked @@ -200,6 +200,18 @@ + +% css settings for a generated file +% for linking, scholarLY converts this all into a css file and links to it +% for printing in header, we do the same but print into the header +% for embedded/inline css, scholarly sorts the option as best it can; if the +% options don't match the divs (say, we have a setting for "foo" class, but there +% is no "foo" class in the document), it is ignored. +\registerOption scholarly.annotate.export.html.generate-css-settings #`() + + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Handling of annotation types for LaTeX output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 67923c0..22c6b26 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -28,6 +28,78 @@ %%%% Export annotations to html file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% Default CSS Settings: +% ~~~~~~~~~~~~~~~~~~~~ +% If the class/id name matches a builtin (such as annotations, annotation, etc.) +% then it is applied to that div (even if the user has distinguished a new class/id +% name for that particular div). This allows default css to still be toggled +% without the user needing to manually rename their stuff to match these. +% OTHERWISE, if it isn't a builtin, scholarLY turns that name (such as +% `my-id-for-something` below) into a string, and applies it to the matching +% class/id at the time of processing. + +#(define default-css-settings + `((by-class . ((full-ann-list . ("background: gray" + "margin: 0.5em" + "line-height: 1.2" + (ul . "list-style-type: none"))) + (each-ann-inner . ((ul . "background: lightgray") + (ul_li . ("background: gray" + "margin: 0.25em")))))) + (by-id . ((my-id-for-something . ("foo: bar")))))) + +% nicely formatted css for header or exported +#(define formatted-css + (let* ((css-type (getOption `(scholarly annotate export html use-css))) + (css-settings (if (eq? css-type 'default) + default-css-settings + (getOption `(scholarly annotate export html + generate-css-settings)))) + (pretty-css "")) + (for-each + (lambda (family) + (for-each + (lambda (member) + (set! pretty-css (string-append pretty-css + (format (cond ((eq? (car family) 'by-class) + "\n.~a {~a }\n") + ((eq? (car family) 'by-id) + "\n#~a {\n~a }\n") + (else "\n~a {~a }\n")) + (car member) + (let ((sub-mem-styles "")) + (for-each + (lambda (sub-member) + (set! sub-mem-styles + (if (string? sub-member) + (format "~a\n ~a;" sub-mem-styles sub-member) + (format "~a\n} ~a {~a" + sub-mem-styles + (let ((multi-segs (string-match "(-|_)" + (symbol->string (car sub-member))))) + (if (not multi-segs) + (car sub-member) + (regexp-substitute #f + multi-segs + 'pre " " 'post))) + (if (string? (cdr sub-member)) + (format "\n ~a;" (cdr sub-member)) + (let* ((sub-lst "")) + (for-each + (lambda (mem) + (set! sub-lst + (format "~a\n ~a;" + sub-lst mem))) + (cdr sub-member)) + sub-lst)))))) + (cdr member)) + sub-mem-styles))))) + (cdr family))) + css-settings) + pretty-css)) + + #(define (indent inpt num) (string-append (make-string num #\space) inpt)) From 98f446404ae3077ff9dab139a34d2179d1a61c6e Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Tue, 14 Mar 2017 21:56:07 -0400 Subject: [PATCH 34/43] trivial, remove unnecessary let* asterisk --- annotate/export-html.ily | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 22c6b26..db63efb 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -85,7 +85,7 @@ 'pre " " 'post))) (if (string? (cdr sub-member)) (format "\n ~a;" (cdr sub-member)) - (let* ((sub-lst "")) + (let ((sub-lst "")) (for-each (lambda (mem) (set! sub-lst From 6558709a8a69a824f16c6ba08db33e1b747d01f0 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Tue, 14 Mar 2017 23:21:05 -0400 Subject: [PATCH 35/43] prints formatted css to header (not totally clean yet, visually-speaking) --- annotate/config.ily | 2 +- annotate/export-html.ily | 15 ++++++++++++--- usage-examples/annotate.ly | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/annotate/config.ily b/annotate/config.ily index c9188ac..5bcf4ed 100644 --- a/annotate/config.ily +++ b/annotate/config.ily @@ -184,7 +184,7 @@ % How to handle CSS upon html export -% #f = no CSS at all +% #`inline = embed css inline (very much not yet implemented) % #`header = print in header; % #`linked = link in header, which also means export css (default or generated) \registerOption scholarly.annotate.export.html.with-css diff --git a/annotate/export-html.ily b/annotate/export-html.ily index db63efb..df00eb2 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -176,16 +176,25 @@ (getOption `(scholarly annotate export html external-css-name))) (else "default-stylesheet.css")))) (append-to-output-stringlist (format - " +" - + ~a -" css-name)))) +" + ;; insert link to css, or directly embed css in header. + (let ((css-method (getOption `(scholarly annotate export html with-css)))) + (cond ((eq? css-method 'linked) + (format "" + css-name)) + ((eq? css-method 'header) + (format "\n\n" formatted-css)))))))) + + ;; wrap everything in the annotations div. this is sort of redundant, but ;; could be useful if projects have multiple bookparts with annotation lists. diff --git a/usage-examples/annotate.ly b/usage-examples/annotate.ly index 2da6546..0d52fb3 100644 --- a/usage-examples/annotate.ly +++ b/usage-examples/annotate.ly @@ -13,6 +13,22 @@ \setOption scholarly.annotate.export.html.props #`(type grob-type message) +\setOption scholarly.annotate.export.html.generate-css-settings + #`((by-class . ((full-ann-list . ("background: gray" + "margin: 0.5em" + "line-height: 1.2" + (ul . "list-style-type: none"))) + (each-ann-inner . ((ul . "background: lightgray") + (ul_li . ("background: gray" + "margin: 0.25em")))))) + (by-id . ((my-id-for-something . ("foo: bar"))))) + +\setOption scholarly.annotate.export.html.use-css + #`generate +\setOption scholarly.annotate.export.html.with-css + #`header + + music = \relative c'{ c4 d e \criticalRemark \with { From 8371f0b2c6fc673593ade07dfbcc3745244f2f1c Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Tue, 14 Mar 2017 23:34:22 -0400 Subject: [PATCH 36/43] formats css prettier --- annotate/export-html.ily | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index df00eb2..3ee97b5 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -63,10 +63,10 @@ (lambda (member) (set! pretty-css (string-append pretty-css (format (cond ((eq? (car family) 'by-class) - "\n.~a {~a }\n") + "\n.~a {~a \n}\n") ((eq? (car family) 'by-id) - "\n#~a {\n~a }\n") - (else "\n~a {~a }\n")) + "\n#~a {~a \n}\n") + (else "\n~a {~a \n}\n")) (car member) (let ((sub-mem-styles "")) (for-each From 7f6deec089484b267649d3491d58af08d84f81be Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Wed, 15 Mar 2017 00:33:59 -0400 Subject: [PATCH 37/43] WIP filling in css formatting procedure 1 of 2 --- annotate/config.ily | 3 +++ usage-examples/annotate.ly | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/annotate/config.ily b/annotate/config.ily index 5bcf4ed..2e5e930 100644 --- a/annotate/config.ily +++ b/annotate/config.ily @@ -158,6 +158,9 @@ (each-ann-props . li) ;; each prop ) +\registerOption scholarly.annotate.export.html.annotations-div-tags + #`((class . "my-annotations") + (id . #f)) % Which props to print to html \registerOption scholarly.annotate.export.html.props diff --git a/usage-examples/annotate.ly b/usage-examples/annotate.ly index 0d52fb3..6aea16c 100644 --- a/usage-examples/annotate.ly +++ b/usage-examples/annotate.ly @@ -14,14 +14,14 @@ #`(type grob-type message) \setOption scholarly.annotate.export.html.generate-css-settings - #`((by-class . ((full-ann-list . ("background: gray" + #`((class . ((full-ann-list . ("background: gray" "margin: 0.5em" "line-height: 1.2" (ul . "list-style-type: none"))) (each-ann-inner . ((ul . "background: lightgray") (ul_li . ("background: gray" "margin: 0.25em")))))) - (by-id . ((my-id-for-something . ("foo: bar"))))) + (id . ((my-id-for-something . ("foo: bar"))))) \setOption scholarly.annotate.export.html.use-css #`generate From a71c56b64fd7d38e9cd575223bbe754c056d6fc3 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Wed, 15 Mar 2017 00:37:10 -0400 Subject: [PATCH 38/43] oops this goes with previous commit --- annotate/export-html.ily | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 3ee97b5..2d119b8 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -40,14 +40,14 @@ % class/id at the time of processing. #(define default-css-settings - `((by-class . ((full-ann-list . ("background: gray" + `((class . ((full-ann-list . ("background: gray" "margin: 0.5em" "line-height: 1.2" (ul . "list-style-type: none"))) (each-ann-inner . ((ul . "background: lightgray") (ul_li . ("background: gray" "margin: 0.25em")))))) - (by-id . ((my-id-for-something . ("foo: bar")))))) + (id . ((my-id-for-something . ("foo: bar")))))) % nicely formatted css for header or exported #(define formatted-css @@ -62,12 +62,20 @@ (for-each (lambda (member) (set! pretty-css (string-append pretty-css - (format (cond ((eq? (car family) 'by-class) + (format (cond ((eq? (car family) 'class) "\n.~a {~a \n}\n") - ((eq? (car family) 'by-id) + ((eq? (car family) 'id) "\n#~a {~a \n}\n") (else "\n~a {~a \n}\n")) - (car member) + (if (eq? (car member) 'full-ann-list) + (let ((anns-tag-redefined + (getChildOption + `(scholarly annotate export html annotations-div-tags) + (car family)))) + (if anns-tag-redefined + anns-tag-redefined + (car member))) + (car member)) (let ((sub-mem-styles "")) (for-each (lambda (sub-member) From 2c17aa8fb2ef69039171809bdaed37160fba7fee Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Wed, 15 Mar 2017 00:54:32 -0400 Subject: [PATCH 39/43] fix use-css functionality, now prints default or custom into header --- annotate/export-html.ily | 22 +++++++++++----------- usage-examples/annotate.ly | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 2d119b8..f3e51db 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -41,18 +41,18 @@ #(define default-css-settings `((class . ((full-ann-list . ("background: gray" - "margin: 0.5em" - "line-height: 1.2" - (ul . "list-style-type: none"))) - (each-ann-inner . ((ul . "background: lightgray") - (ul_li . ("background: gray" - "margin: 0.25em")))))) - (id . ((my-id-for-something . ("foo: bar")))))) + "margin: 0.5em" + "line-height: 1.2" + (ul . "list-style-type: none"))) + (annotation . ((ul . "background: lightgray") + (ul_li . "margin: 0.25em"))) + (todo . ("background: red")) + (question . ("background: green")))) + (id . ((my-unique-annotations-list . ("foo: bar")))))) % nicely formatted css for header or exported -#(define formatted-css - (let* ((css-type (getOption `(scholarly annotate export html use-css))) - (css-settings (if (eq? css-type 'default) +#(define (formatted-css css-type) + (let* ((css-settings (if (eq? css-type 'default) default-css-settings (getOption `(scholarly annotate export html generate-css-settings)))) @@ -200,7 +200,7 @@ (format "" css-name)) ((eq? css-method 'header) - (format "\n\n" formatted-css)))))))) + (format "\n\n" (formatted-css css-type))))))))) diff --git a/usage-examples/annotate.ly b/usage-examples/annotate.ly index 6aea16c..c7f6638 100644 --- a/usage-examples/annotate.ly +++ b/usage-examples/annotate.ly @@ -58,7 +58,7 @@ music = \relative c'{ } \new Voice = "voice two" { \voiceTwo - \criticalRemark \with { + \todo \with { message="A note about the second voice." } NoteHead From 5b28f0d149b0c69d9f36f83dea432122dd275188 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Wed, 15 Mar 2017 01:49:36 -0400 Subject: [PATCH 40/43] applies optional 'annotations' div class/id if specified --- annotate/export-html.ily | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index f3e51db..f337871 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -126,11 +126,26 @@ (let* ((trailing-line (if (= nest-level 0) "\n" "")) (div-type (symbol->string (getChildOption `(scholarly annotate export html divs) type))) - (class (classify-html-tag (if (string? ann-or-string) ann-or-string "annotation"))) + (class (classify-html-tag (if (string? ann-or-string) + (if (equal? ann-or-string "annotations") + (let ((anns-class-renamed (assq-ref (getOption + `(scholarly annotate export html annotations-div-tags)) + 'class))) + (if anns-class-renamed + anns-class-renamed + ann-or-string)) + ann-or-string) + "annotation"))) (id - (let ((html-id (and (not (string? ann-or-string)) - (assq-ref ann-or-string 'html-id)))) - (if html-id (idify-html-tag html-id) ""))) + (if (equal? ann-or-string "annotations") + (let ((anns-id-renamed (assq-ref (getOption + `(scholarly annotate export html annotations-div-tags)) + 'id))) + (if anns-id-renamed + (idify-html-tag anns-id-renamed) "")) + (let ((html-id (and (not (string? ann-or-string)) + (assq-ref ann-or-string 'html-id)))) + (if html-id (idify-html-tag html-id) "")))) (div-tags (delimit-html-tags (list div-type class id))) (div-begin (format "~a~a" (indent div-tags nest-level) trailing-line))) (append-to-output-stringlist div-begin))) From 38448b178ad6c434a71d971ac34fa45b931064ce Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Wed, 15 Mar 2017 11:01:04 -0400 Subject: [PATCH 41/43] updates example generated css --- usage-examples/annotate.ly | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/usage-examples/annotate.ly b/usage-examples/annotate.ly index c7f6638..cc12619 100644 --- a/usage-examples/annotate.ly +++ b/usage-examples/annotate.ly @@ -14,14 +14,23 @@ #`(type grob-type message) \setOption scholarly.annotate.export.html.generate-css-settings - #`((class . ((full-ann-list . ("background: gray" - "margin: 0.5em" - "line-height: 1.2" - (ul . "list-style-type: none"))) - (each-ann-inner . ((ul . "background: lightgray") - (ul_li . ("background: gray" - "margin: 0.25em")))))) - (id . ((my-id-for-something . ("foo: bar"))))) + #`((class . ((full-ann-list . ("margin: 1em" + "padding-left: 0" + (ul . "list-style-type: none"))) + (annotation . ("margin-top: 1em" + "margin-left: 0.25" + "background: #b0b0bb" + (ul . "padding-left: 0"))) + (todo . ("background: #caa8a8" + "color: darkred")) + (type . ("color: white" + "background: #444444")))) + (id . ((my-id-for-something . ("foo: bar")))) + ;; "tag" is just a generic key here.. anything other than + ;; "class" or "id" just means that the elements within it + ;; will be printed without "." or "#". + (tag . ((body . ("width: 50%" + "min-width: 400px"))))) \setOption scholarly.annotate.export.html.use-css #`generate From da8ae303cdfe94e266e4dd0c4db48abce599ea69 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Wed, 15 Mar 2017 13:02:53 -0400 Subject: [PATCH 42/43] outputs generated css file if option selected --- annotate/export-html.ily | 39 ++++++++++++++++++++++++-------------- usage-examples/annotate.ly | 5 +++-- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index f337871..9dceb76 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -28,6 +28,9 @@ %%%% Export annotations to html file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +#(use-modules (ice-9 rdelim)) +#(use-modules (ice-9 regex)) + % Default CSS Settings: % ~~~~~~~~~~~~~~~~~~~~ @@ -188,16 +191,18 @@ \register-export-routine html #(lambda () - (let ((full-doc (getOption `(scholarly annotate export html full-document)))) + (let* ((full-doc (getOption `(scholarly annotate export html full-document))) + (css-method (getOption `(scholarly annotate export html with-css))) + (css-type (getOption `(scholarly annotate export html use-css))) + (css-name (cond ((eq? css-type 'generate) + (getOption `(scholarly annotate export html generate-css-name))) + ((eq? css-type 'external) + (getOption `(scholarly annotate export html external-css-name))) + (else "default-stylesheet.css")))) ;; If option is True, add the header and body (if full-doc - (let* ((css-type (getOption `(scholarly annotate export html use-css))) - (css-name (cond ((eq? css-type 'generate) - (getOption `(scholarly annotate export html generate-css-name))) - ((eq? css-type 'external) - (getOption `(scholarly annotate export html external-css-name))) - (else "default-stylesheet.css")))) + (begin (append-to-output-stringlist (format " @@ -209,13 +214,19 @@ " - ;; insert link to css, or directly embed css in header. - (let ((css-method (getOption `(scholarly annotate export html with-css)))) - (cond ((eq? css-method 'linked) - (format "" - css-name)) - ((eq? css-method 'header) - (format "\n\n" (formatted-css css-type))))))))) + ;; insert link to css, or directly embed css in header. + (cond ((eq? css-method 'linked) + (format "" + css-name)) + ((eq? css-method 'header) + (format "\n\n" (formatted-css css-type)))))) + ;; if we want to generate and link to a seperate .css file + (if (and (eq? css-method 'linked) + (or (eq? css-type 'generate) + (eq? css-type 'default))) + (with-output-to-file + css-name ; css-name + (lambda () (write-line (formatted-css css-type))))))) diff --git a/usage-examples/annotate.ly b/usage-examples/annotate.ly index cc12619..ac5a0a7 100644 --- a/usage-examples/annotate.ly +++ b/usage-examples/annotate.ly @@ -35,8 +35,9 @@ \setOption scholarly.annotate.export.html.use-css #`generate \setOption scholarly.annotate.export.html.with-css - #`header - + #`linked + +%\displayOptions music = \relative c'{ c4 d e From 141fa37c7de337b40f7baeb484b70ac4a0d7c115 Mon Sep 17 00:00:00 2001 From: Jeffery Shivers Date: Mon, 10 Apr 2017 21:29:20 -0400 Subject: [PATCH 43/43] adds comments --- annotate/export-html.ily | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/annotate/export-html.ily b/annotate/export-html.ily index 9dceb76..a484fe2 100644 --- a/annotate/export-html.ily +++ b/annotate/export-html.ily @@ -61,8 +61,10 @@ generate-css-settings)))) (pretty-css "")) (for-each + ;; family = a group named .class, #id, or anything else (lambda (family) (for-each + ;; member = each .class, #id, or anything else (lambda (member) (set! pretty-css (string-append pretty-css (format (cond ((eq? (car family) 'class) @@ -79,23 +81,31 @@ anns-tag-redefined (car member))) (car member)) + ;; sub-mem-styles = a list of everything in each sub-member: + ;; sub-member { sub-mem-styles } (let ((sub-mem-styles "")) (for-each + ;; sub-member = list of strings and/or pairs (lambda (sub-member) (set! sub-mem-styles (if (string? sub-member) + ;; string gets printed literally (format "~a\n ~a;" sub-mem-styles sub-member) + ;; pairs are formatted like members and squeezed + ;; between the first and last delimiters (format "~a\n} ~a {~a" sub-mem-styles (let ((multi-segs (string-match "(-|_)" (symbol->string (car sub-member))))) (if (not multi-segs) (car sub-member) + ;; turn "ul_li" or "ul-li" into "ul li" (regexp-substitute #f multi-segs 'pre " " 'post))) (if (string? (cdr sub-member)) (format "\n ~a;" (cdr sub-member)) + ;; it is a list of strings (let ((sub-lst "")) (for-each (lambda (mem)