Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mdbenito committed May 15, 2021
2 parents 7214cc4 + f026b76 commit bb51eed
Show file tree
Hide file tree
Showing 30 changed files with 408 additions and 210 deletions.
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ For Windows, the path (usually?) is
\Users\YourUser\AppData\Roaming\TeXmacs\plugins
```

You can activate a menu with Tools -> Markdown plugin.
You can activate a menu with `Tools -> Markdown plugin`.

## Hugo support

Expand All @@ -37,8 +37,8 @@ converted from TeXmacs, including setting frontmatter values and extensions
like footnotes and ~~striked through text~~.

Setting values for the frontmatter is suported via a dedicated macro defined
in `hugo.ts`. To use it first insert the Markdown -> Hugo package in Document
-> Style -> Add package or using plus sign in the focus bar.
in `hugo.ts`. To use it first insert the `Markdown -> Hugo` package in
`Document -> Style -> Add package` or using the plus sign in the focus bar.

Now you can type `\hugo-front` and input any number of key|value pairs as
arguments, one argument each. That is: type `\hugo-front`, then use structured
Expand All @@ -49,18 +49,27 @@ dates (insert with `\date`) are supported as values. To enter a list, input

### Supported shortcodes

* Figures are converted to `{{< figure … >}}`
* For arbitrary shortcodes, use `\hugo-short`.
* Citations are automatically detected and converted to `{{< cite ref >}}`,
and all of them are gathered in the frontmatter as well, for indization by
Hugo's taxonomy system.
* Probably more…
Some of the texmacs markdown requires custom shortcodes and layouts. You can
find them in `extensions/hugo`. Just copy the partials and shortcodes to your
Hugo project.

* Figures are converted to `{{< tmfigure … >}}`. This is a simplified version
of Hugo's `{{<figure>}}`, which can have `.Inner` content. This is required
e.g. to have citations in captions or arbitrary markup.
* To introduce any shortcode in a TeXmacs document, you can use the macro
`\hugo-short`.
* Citations are automatically detected and converted to
`{{< cite ref1 ref2 ... >}}`, and all of them are gathered in the frontmatter
as well, for indization by Hugo's taxonomy system. The presentation of the
label itself is done using CSS. Include the partial `ref_labels.html.html`
in the document `<head>` for that.
* Bibliography is rendered with the `references.html.html` template.

# Known issues

* The converter can break with malformed or unexpected input, like markup
inside tags whose values should be strings (although many cases are
“handled”)
inside tags whose values should be strings, although some cases are (a bit
sloppily) handled.
* Error reporting is rather lacking. Run TeXmacs in a console to see stack
traces and such in case you are running into problems.
* No tables (yet)!
Expand Down
8 changes: 4 additions & 4 deletions doc/markdown.en.tm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
\\Users\\YourUser\\AppData\\Roaming\\TeXmacs\\plugins
</shell-code>

You can activate a menu with <submenu|Tools|Markdown plugin>.
You can activate a menu with <menu|Tools|Markdown plugin>.

<subsection|Hugo support>

Expand All @@ -46,9 +46,9 @@
extensions like footnotes and <strike-through|striked through text>.

Setting values for the frontmatter is suported via a dedicated macro
defined in <code*|hugo.ts>. To use it first insert the
<submenu|Markdown|Hugo> package in <subsubmenu|Document|Style|Add package>
or using plus sign in the focus bar.
defined in <code*|hugo.ts>. To use it first insert the <menu|Markdown|Hugo>
package in <menu|Document|Style|Add package> or using the plus sign in the
focus bar.

Now you can type <verbatim|\\hugo-front> and input any number of key\|value
pairs as arguments, one argument each. That is: type
Expand Down
53 changes: 53 additions & 0 deletions extensions/hugo/partials/citation.html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{ $key := index . "key" }}
{{ $page := index . "page" }}
{{ $linkOthers := default true (index . "linkOthers") }}
{{ $bib := site.Data.bibliography.references }}
{{ with $entries := where $bib "id" $key }}
{{ $entry := index $entries 0 }}
{{ $year := (index $entry.issued 0).year }}
<span class="citation-title">{{ $entry.title }}</span>,
<span class="citation-authors">
{{ range $i, $author := $entry.author }}
{{ printf "%s %s" $author.given $author.family }}
{{- if lt $i (sub (len $entry.author) 1)}}, {{end}}
{{- end -}}.
</span>
{{ with index $entry "container-title" }}
<span class="citation-publication">{{.}}</span>
{{ end }}
<span class="citation-date">({{ $year }})</span>
{{ with $entry.URL }}
<a class="citation-link" href="{{.}}">
Publication <i class="fa fa-external-link-alt citation-url"></i>
</a>
{{ end }}
{{ with $entry.note }}
{{ range split . "\n" }}
{{ if hasPrefix . "code:" }}
<a class="citation-link" {{ printf "href=%q" (trim (substr . 6) " ") | safeHTMLAttr }}>
Code <i class="fa fa-external-link-alt citation-url"></i>
</a>
{{ else if hasPrefix . "video:" }}
<a class="citation-link" {{ printf "href=%q" (trim (substr . 6) " ") | safeHTMLAttr }}>
Video <i class="fa fa-external-link-alt citation-url"></i>
</a>
{{ end }}
{{ end }}
{{ end }}
{{ with $term := index (site.Taxonomies.refs) $key }}
{{ if $linkOthers }}
{{ with $total := len (where $term.Pages "Page.RelPermalink" "ne" $page.RelPermalink) }}
<a class="d-inline-block pl-4 citation-link" href="{{ $term.Page.RelPermalink }}">
&mdash; {{ $total }} other item {{- cond (gt $total 1) "s" "" }}
in this site reference {{- cond (gt $total 1) "" "s" }} this.
</a>
{{ end }}
{{ end }}
{{ else }}
<div class="alert alert-danger">
Reference "{{$key}}" missing in taxonomy "refs".
</div>
{{ end }}
{{ else }}
<strong>Wrong citekey: {{ $key }}</strong>
{{ end }}
19 changes: 19 additions & 0 deletions extensions/hugo/partials/ref_labels.html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{/*Include this in the document header*/}}
{{ with .Params.refs }}
<style>
{{ range $key := . }}
{{ $parts := split $key "_" }}
{{ $cite := printf "%s%s%s" (substr (index $parts 0 | title) 0 3) (substr (index $parts 2) 2) (upper (substr (index $parts 1) 0 1)) }}
li#refs-{{$key}}::marker {
content: '[{{$cite}}] ';
font-weight: 600;
font-variant: small-caps;
}

a.cite-{{$key}}::before {
content: '{{$cite}}';
}

{{ end }}
</style>
{{ end }}
21 changes: 21 additions & 0 deletions extensions/hugo/partials/references.html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<section>
{{- if gt (.Page.Scratch.Get "citations" | uniq | sort) (.Page.Params.refs | uniq | sort) -}}
<div class="alert alert-danger">
There are citations in the text which are not present in the
<code>refs</code> section of the frontmatter.
<pre>{{ .Page.Scratch.Get "citations" | uniq | sort }}</pre>
<pre>{{ .Page.Params.refs | uniq | sort }}</pre>
</div>
{{- end -}}
{{ if .Page.Params.refs }}
<h1>References</h1>
<ul class="references">
{{ range $index, $key := default slice .Page.Params.refs }}
{{/* We use CSS in ref_labels.html.html to decorate the li elements with the citation labels */}}
<li id="refs-{{$key}}">
{{ partial "citation.html.html" (dict "page" $.Page "key" $key) }}
</li>
{{ end }}
</ul>
{{ end }}
</section>
10 changes: 10 additions & 0 deletions extensions/hugo/shortcodes/cite.html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- with .Params -}}
{{- $citations := slice -}}
{{- range $key := . -}}
{{- $.Page.Scratch.Add "citations" (slice $key) -}}
{{/* We use CSS in ref_labels.html.html create the classes */}}
{{- $html := printf "<a class=\"cite-%s\" href=\"#refs-%s\"></a>" $key $key -}}
{{- $citations = $citations | append $html -}}
{{- end -}}
<span class="citation">[{{ delimit $citations ", " | safeHTML }}]</span>
{{- end -}}
1 change: 1 addition & 0 deletions extensions/hugo/shortcodes/references.html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ partial "references.html.html" . }}
29 changes: 29 additions & 0 deletions extensions/hugo/shortcodes/tmfigure.html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{/* Adapted from Hugo's figure shortcode. https://gohugo.io/ */}}
<figure{{ with .Get "class" }} class="{{ . }}"{{ end }}>
{{- if .Get "link" -}}
<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>{{- end }}
{{ $src := .Get "src"}}
{{- with .Page.Resources.GetMatch $src }}
{{- $src = .RelPermalink }}
{{- end }}
<img src="{{$src | safeURL}}"
{{- if or (.Get "alt") (.Get "caption") }}
alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify | plainify }}{{ end }}"
{{- end -}}
{{- with .Get "width" }} width="{{ . }}"{{ end -}}
{{- with .Get "height" }} height="{{ . }}"{{ end -}}
/>
{{- if .Get "link" }}</a>{{ end -}}
{{- if or (.Get "title") (.Get "caption") (.Get "attr") .Inner -}}
<figcaption>
{{ with (.Get "title") -}}
<h4>{{ . }}</h4>
{{- end -}}
{{- with .Inner -}}
<p>
{{ . }}
</p>
{{- end -}}
</figcaption>
{{- end }}
</figure>
26 changes: 0 additions & 26 deletions packages/aai-tfl.ts

This file was deleted.

Loading

0 comments on commit bb51eed

Please sign in to comment.