Skip to content

Commit 3ee7295

Browse files
authored
Merge develop into master
Marginal figures, numbered sections, improved counters, fixes
2 parents bb51eed + c8e19da commit 3ee7295

File tree

12 files changed

+321
-85
lines changed

12 files changed

+321
-85
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{{/* Figures at the margin.
2+
3+
Batteries not included. Requires lots of styles.
4+
Some content breaks paragraphs!
5+
6+
Usage:
7+
8+
{{< sidefigure class="optional CSS class" valign=<top,center,bottom>
9+
numbered=numbered raw=raw header="Some text" >}}
10+
Content here.
11+
{{< /sidefigure >}}
12+
Parameters:
13+
class: one or more CSS class names
14+
valign: where the bottom of the sidenote will be placed wrt the inline content.
15+
"top" is the default: the sidenote starts at the height it is inserted.
16+
"center" shifts it by 50% upwards. "bottom" by 100%.
17+
numbered: whether to prefix the content with an autoincreased counter and
18+
display it in the main text.
19+
markdownify: whether to process .Inner with the markdown renderer. This is a
20+
HACK, remove it. Will break nested shortcodes.
21+
raw: set to true if there are nested shortcodes, e.g. {{<figure>}} or {{<toc>}}
22+
header: This will be rendered bold and centered above the content
23+
*/}}
24+
{{- $this := . -}}
25+
{{- $class := "sidenote" -}}
26+
{{- with .Get "valign" -}}
27+
{{- if (eq . "center") -}}
28+
{{- $class = printf "%s %s" $class (safeHTMLAttr "sidenote-center") -}}
29+
{{- end -}}
30+
{{- if (eq . "bottom") -}}
31+
{{- $class = printf "%s %s" $class (safeHTMLAttr "sidenote-bottom") -}}
32+
{{- end -}}
33+
{{- end -}}
34+
{{- with .Get "class" -}}
35+
{{- $class = printf "%s %s" $class (safeHTMLAttr .) -}}
36+
{{- end -}}
37+
{{- $refText := "" -}}
38+
{{- $anchor := "" -}}
39+
{{- with .Get "numbered" -}}
40+
{{- $this.Page.Scratch.Add "sidenote-counter" 1 -}}
41+
{{- $refText = printf "Figure %d. " ($this.Page.Scratch.Get "sidenote-counter") -}}
42+
{{- $anchor = printf "<span class=\"sidenote-ref\">%s</span>" $refText -}}
43+
{{- end -}}
44+
{{- $anchor | safeHTML -}}
45+
<span class="{{$class}}">
46+
<span class="sidefigure">
47+
{{ $src := .Get "src"}}
48+
{{- with .Page.Resources.GetMatch $src }}
49+
{{- $src = .RelPermalink }}
50+
{{- end }}
51+
<img src="{{$src | safeURL}}" alt="{{.Get "title"}}">
52+
</span>
53+
<span class="sidefigure-caption">
54+
{{- with .Get "title" -}}
55+
<span class="sidenote-title">{{.}}</span>
56+
{{- end -}}
57+
{{ if or (.Get "caption") .Inner }}
58+
<span class="sidenote-paragraph text-center">
59+
{{- $anchor | safeHTML -}}
60+
<span class="font-italic smaller">
61+
{{ with .Get "caption"}}
62+
{{ . | markdownify }}
63+
{{ end }}
64+
{{ with .Inner }}
65+
{{ if $.Get "markdownify" }}
66+
{{ . | markdownify }}
67+
{{ else }}
68+
{{ . }}
69+
{{ end }}
70+
{{ end }}
71+
</span>
72+
</span>
73+
{{ end }}
74+
</span>
75+
</span>
76+
{{- /**/ -}}

progs/init-markdown.scm

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
(define-preferences
1717
("texmacs->markdown:flavour" "vanilla" ignore)
1818
("texmacs->markdown:paragraph-width" 79 ignore)
19-
("texmacs->markdown:show-menu" "off" ignore))
19+
("texmacs->markdown:show-menu" "off" ignore)
20+
("texmacs->markdown:numbered-sections" "on" ignore))
2021

2122
(define-format markdown
2223
(:name "Markdown")
@@ -54,9 +55,10 @@
5455
(lazy-menu (markdown-menus) markdown-menu tools-menu)
5556

5657
(define (markdown-menu-show?)
57-
(== (get-preference "texmacs->markdown:show-menu") "on"))
58+
(preference-on? "texmacs->markdown:show-menu"))
5859

59-
(delayed (:idle 1)
60-
(menu-bind tools-menu
61-
(former)
62-
("Markdown plugin" (toggle-preference "texmacs->markdown:show-menu"))))
60+
(delayed (:idle 1000)
61+
(lazy-define-force tools-menu)
62+
(menu-bind tools-menu
63+
(former)
64+
("Markdown plugin" (toggle-preference "texmacs->markdown:show-menu"))))

progs/markdown-menus.scm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
("Vanilla" (markdown-set-flavour "vanilla"))
3737
("Hugo" (markdown-set-flavour "hugo")))
3838
("Paragraph width" (interactive markdown-set-paragraph-width))
39+
("Numbered sections" (toggle-preference "texmacs->markdown:numbered-sections"))
3940
---
4041
("Help" (load-help-article "markdown")))
4142

progs/markdownout.scm

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
(lambda (x)
101101
(cond ((tm-is? x 'date) (second x))
102102
((tm-is? x 'tuple)
103-
(string-append "\n" (list->yaml (cdr x) 2)))
103+
(string-append "\n" (list->yaml (list-sort (cdr x) string<=?) 2)))
104104
((tuple? x) (string-append "\n" (list->yaml x 2)))
105105
((bool? x) x)
106106
((string? x) (string-quote x))))) ; quote everything else
@@ -196,15 +196,14 @@
196196
(define (md-doc-title x)
197197
(with title (md-string (serialize-markdown* (cdr x)))
198198
(if (hugo-extensions?)
199-
(md-hugo-frontmatter `(hugo-front "title" ,title))
200-
title)))
199+
(serialize-markdown* `(hugo-front "title" ,title))
200+
(serialize-markdown* `(document ,title "")))))
201201

202202
(define (md-doc-subtitle x)
203-
(display "FIXME: append subtitle to title")
204203
(with subtitle (md-string (serialize-markdown* (cdr x)))
205204
(if (hugo-extensions?)
206-
(md-hugo-frontmatter `(hugo-front "subtitle" ,subtitle))
207-
subtitle)))
205+
(serialize-markdown* `(hugo-front "subtitle" ,subtitle))
206+
(serialize-markdown* `(document ,subtitle)))))
208207

209208
(define (md-doc-author x)
210209
; TODO? We might want to extract other info
@@ -235,7 +234,7 @@
235234
(define (md-abstract x)
236235
(if (hugo-extensions?)
237236
(md-hugo-frontmatter `(hugo-front "summary" ,(serialize-markdown* (cdr x))))
238-
(md-document (md-style `(em ,(cdr x))))))
237+
(md-paragraph `(concat (strong "Abstract: ") (em ,(cdr x))))))
239238

240239
(define (md-paragraph p)
241240
;; FIXME: arguments of Hugo shortcodes shouldn't be split
@@ -430,18 +429,31 @@
430429
(alt (if (list-2? payload) (second payload) "")))
431430
(string-append "![" alt "](" (force-string src) ")")))
432431

433-
(define (md-figure-sub x type . args)
434-
(let* ((payload (cdr x))
435-
(src (force-string (car payload)))
432+
; FIXME: clear this mess with figures, don't expect img as content, etc.
433+
(define (md-figure-sub payload)
434+
(let* ((src (force-string (car payload)))
436435
(title
437436
(with-globals 'num-line-breaks 0 ; Don't break lines in 'document
438437
(string-concatenate (map serialize-markdown* (cdr payload))))))
439-
(if (hugo-extensions?)
440-
(md-hugo-shortcode `(,type (src ,src) ,@args) title)
441-
(md-image (list 'image src title)))))
438+
(list src title)))
442439

443440
(define (md-figure type . args)
444-
(lambda (x) (md-figure-sub x type args)))
441+
(lambda (x)
442+
(with params (md-figure-sub (cdr x))
443+
(if (hugo-extensions?)
444+
(md-hugo-shortcode `(,type (src ,(car params)) ,args) (cadr params))
445+
(md-image (list 'image (car params) (cadr params)))))))
446+
447+
(define (md-marginal-figure type . args)
448+
(lambda (x)
449+
(let ((params (md-figure-sub (cddr x)))
450+
(vpos (cadr x)))
451+
(if (hugo-extensions?)
452+
(md-hugo-shortcode `(,type (valign ,(marginal-style vpos))
453+
(src ,(car params))
454+
,args)
455+
(cadr params))
456+
(md-image (list 'image (car params) (cadr params)))))))
445457

446458

447459
(define (md-footnote x)
@@ -488,8 +500,10 @@
488500
(string-append (serialize-markdown* inner)
489501
"{{</" (symbol->string (car x)) ">}}"))))
490502
(string-trim-both
491-
(string-recompose-space
492-
`("{{<" ,shortcode ,@(map process-one arguments) ">}}" ,content))))))
503+
(string-append
504+
(string-recompose-space
505+
`("{{<" ,shortcode ,@(map process-one arguments) ">}}"))
506+
content)))))
493507

494508
(define (md-toc x)
495509
(if (hugo-extensions?)
@@ -501,16 +515,29 @@
501515
(md-hugo-shortcode '(references))
502516
(md-style '(strong "Bibliography not implemented for raw Markdown"))))
503517

504-
(define (md-sidenote x)
518+
(define marginal-styles-table
519+
(list->ahash-table '(("b" . "bottom") ("c" . "center")
520+
("t" . "top") ("normal" . "right"))))
521+
522+
(define (marginal-style s)
523+
(ahash-ref marginal-styles-table s))
524+
525+
(define (md-sidenote-sub x numbered?)
505526
(if (hugo-extensions?)
506-
(let ((styles (list->ahash-table '(("b" . "bottom") ("c" . "center")
507-
("t" . "top") ("normal" . "right"))))
527+
(let ((numbered (if numbered? '((numbered "numbered")) '()))
508528
(args (cdr x)))
509529
(md-hugo-shortcode
510-
`(sidenote (halign ,(ahash-ref styles (first args)))
511-
(valign ,(ahash-ref styles (second args))))
530+
(append `(sidenote (halign ,(marginal-style (first args)))
531+
(valign ,(marginal-style (second args))))
532+
numbered)
512533
(third args)))
513-
(md-footnote (list 'footnote (third args)))))
534+
(md-footnote (list 'footnote (third (cdr x))))))
535+
536+
(define (md-sidenote x)
537+
(md-sidenote-sub x #t))
538+
539+
(define (md-sidenote* x)
540+
(md-sidenote-sub x #f))
514541

515542
(define (md-explain-macro x)
516543
; FIXME: this will break with nested macros (tt style will be interrupted)
@@ -633,17 +660,23 @@
633660
(list 'footnote md-footnote)
634661
(list 'todo md-todo)
635662
(list 'image md-image)
636-
(list 'small-figure (md-figure 'tmfigure))
637-
(list 'big-figure (md-figure 'tmfigure))
638-
(list 'wide-figure (md-figure 'tmfigure 'class "wide-figure"))
663+
(list 'small-figure (md-figure 'tmfigure 'numbered "numbered"))
664+
(list 'small-figure* (md-figure 'tmfigure))
665+
(list 'big-figure (md-figure 'tmfigure 'numbered "numbered"))
666+
(list 'big-figure* (md-figure 'tmfigure))
667+
(list 'wide-figure (md-figure 'tmfigure 'class "wide-figure"
668+
'numbered "numbered"))
669+
(list 'wide-figure* (md-figure 'tmfigure 'class "wide-figure"))
670+
(list 'marginal-figure (md-marginal-figure 'sidefigure))
671+
(list 'marginal-figure* (md-marginal-figure 'sidefigure))
639672
(list 'hlink md-hlink)
640673
(list 'tags md-hugo-tags) ; Hugo extension (DEPRECATED)
641674
(list 'hugo-short md-hugo-shortcode) ; Hugo extension
642675
(list 'hugo-front md-hugo-frontmatter) ; Hugo extension
643676
(list 'table-of-contents md-toc) ; Hugo extension
644677
(list 'bibliography md-bibliography) ; TfL extension
645678
(list 'marginal-note md-sidenote) ; TfL extension
646-
(list 'marginal-note* md-sidenote) ; TfL extension (TO DO)
679+
(list 'marginal-note* md-sidenote*) ; TfL extension
647680
(list 'explain-macro md-explain-macro)
648681
(list 'tmdoc-copyright md-tmdoc-copyright)
649682
))

0 commit comments

Comments
 (0)