├── .gitmodules ├── LICENSE ├── Makefile ├── README.md ├── test.markdown └── xmark.xsl /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tufte-css"] 2 | path = tufte-css 3 | url = https://github.com/edwardtufte/tufte-css.git 4 | [submodule "cmark"] 5 | path = cmark 6 | url = https://github.com/jgm/cmark.git 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Antonio Vieiro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # CMARK must point to the "cmark" executable 2 | CMARK=/Users/antonio/SOFTWARE/CMARK/bin/cmark 3 | # And XSLTPROC must point to the xsltproc executable 4 | XSLTPROC=/usr/bin/xsltproc 5 | 6 | all: test.html test-notoc.html 7 | 8 | test-notoc.html: test.markdown xmark.xsl 9 | $(CMARK) -t xml test.markdown | $(XSLTPROC) --novalid --nonet --stringparam generate.toc no xmark.xsl - > test-notoc.html 10 | 11 | test.html: test.markdown xmark.xsl Makefile 12 | $(CMARK) -t xml test.markdown > test.xml 13 | $(XSLTPROC) --novalid --nonet xmark.xsl test.xml > test.html 14 | 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xmark 2 | 3 | A simple XSLT stylesheet that generates [tufte-css](https://github.com/edwardtufte/tufte-css) powered HTML from [CommonMark](http://commonmark.org) markdown documents. 4 | 5 | More information [available here](http://vieiro.github.io/xmark/). 6 | 7 | -------------------------------------------------------------------------------- /test.markdown: -------------------------------------------------------------------------------- 1 | # xmark = Markdown + Tufte CSS 2 | ## Antonio Vieiro 3 | 4 | ## A brief introduction 5 | 6 | [Markdown](https://daringfireball.net/projects/markdown/) is a plain text format for writing structured documents, based on formatting conventions from email and usenet. It was developed in 2004 by John Gruber. 7 | 8 | [CommonMark](http://commonmark.org) is a proposal for a standard, **unambiguous syntax specification for Markdown**, along with a **suite of comprehensive tests** to validate Markdown implementations against this specification. It was created by a group of [Markdown fans](http://commonmark.org). 9 | 10 | [tufte-css](https://edwardtufte.github.io/tufte-css/) provides tools to style web articles using the ideas demonstrated by Edward Tufte's books and handouts. It was created by [Dave Liepmann](http://www.daveliepmann.com/) in late 2015 and is now an Edward Tufte project. 11 | 12 | [xmark](https://github.com/vieiro/xmark) is a simple XSLT stylesheet that transforms CommonMark compliant plain text documents ([see the source of this one here](https://raw.githubusercontent.com/vieiro/xmark/master/test.markdown)), with some additional conventions, into tufte-css styled web pages. 13 | 14 | This document enumerates the goals of xmark, its conventions and explains how to use it. 15 | 16 | ## xmark goals 17 | 18 | xmark has two main goals: 19 | 20 | ### I: Generate tufte-css styled web pages 21 | 22 | The first goal of xmark is to generate tufte-css styled web pages from plain text files that follow the CommonMark specification. 23 | 24 | ### II: Serve as an experimentation tool 25 | 26 | The second goal of xmark is to serve as a tool to manipulate the XML structure generated with CommonMark's cmark parser. By modifying a simple XSLT one can generate all sort of structured documents out from plain CommonMark text files. 27 | 28 | ## xmark conventions 29 | 30 | Nor Markdown nor CommonMark support document metadata so, for instance, there is no standard way to specify a title in a CommonMark document. It is not possible either to mark a paragraph as an epigraph, or as a figure caption, or as a margin note. 31 | 32 | [*Def. xmark convention*: a simple rule that allows emulating metadata in CommonMark markdown documents.](sidenote) These limitations in Markdown, and in the CommonMark standard, are overcome in xmark by means of conventions, that assign special meanings to paragraphs. This section lists these conventions: 33 | 34 | ### Document title convention 35 | 36 | > The document title is the first section of the document with level one. This is, the first paragraph tagged with a single '#' in the markdown document. 37 | 38 | It does not matter where you hide the first level one tag in your markdown document: xmark always places the title as the first paragraph of the document, using an ```
``` tufte-css element. The subtitle does not appear in the Table of Contents.
58 |
59 | ### Epigraph convention
60 |
61 | CommonMark does not support epigraphs, but allows for nested block quotes. xmark makes use of this feature, making the double-nested block quotes work as epigraphs:
62 |
63 | > Two-level nested block quotes (i.e., a pagraph starting with ```>>```) are always transformed to epigraphs.
64 |
65 | So, for instance, this text:
66 |
67 | ``` markdown
68 | >> xmark epigraphs are started with two ```>``` at the beginning of the paragraph.
69 | ```
70 |
71 | Will generate a tufte-css epigraph like this one:
72 |
73 | >> xmark epigraphs are started with two ```>``` at the beginning of the paragraph.
74 |
75 | Epigraphs may also contain a footer using plain HTML, but you will have to specify the ```footer``` and ```cite``` in plain HTML, like this one:
76 |
77 | ```markdown
78 | >> I do not paint things, I paint only the differences between things.
79 | >>
81 | ```
82 |
83 | That gets translated in the following HTML:
84 |
85 | >> I do not paint things, I paint only the differences between things.
86 | >>
87 |
88 | ### Sidenote convention
89 |
90 | Nor markdown nor CommonMark support sidenotes [Sidenotes are like footnotes, except they don't force the user to scroll the page](sidenote).
91 |
92 | Markdown uses the ```[link text](url)``` structure to define links. xmark abuses this structure with the following convention:
93 |
94 | > Sidenotes are normal markdown links that use the word ```sidenote``` as its url.
95 |
96 | Sidenote numbers are automatically generated, so there's no need to worry about that detail.
97 |
98 | ``` markdown
99 | This is a normal paragraph with a
100 | sidenote [Write your sidenotes
101 | inside square brackets and then
102 | add a ```(sidenote)```
103 | url.](sidenote).
104 | ```
105 |
106 | Will produce the following paragraph with a sidenote:
107 |
108 | This is a normal paragraph with a sidenote [Write your sidenotes inside square brackets and then add a ```(sidenote)``` url.](sidenote).
109 |
110 | As in tufte-css, sidenotes (and margin notes, below) are visible in wider screens, but are hidden in smaller screens. In these smaller screens, the symbol ⊕ (``⊕``) or the sidenote number can be tapped to view the content.
111 |
112 | ### Margin note convention
113 |
114 | Margin notes are just like sidenotes, but do not have footnote-style numbers. The xmark convention for margin notes is similar to the previous convention:
115 |
116 | > To create a margin note write a normal markdown link, but use the word ```margin``` as the url.
117 |
118 | So, for instance, the markdown text:
119 |
120 | ```markdown
121 | For example, this paragraph has a
122 | [Margin note text here](margin)
123 | margin note.
124 | ```
125 |
126 | Will result in the following paragraph with a margin note:
127 |
128 | For example, this paragraph has a [Margin note text here](margin) margin note.
129 |
130 |
131 | ### Figure convention
132 |
133 | CommonMark supports images by using the construction:
134 |
135 | ```markdown
136 | ]
137 | ```
138 |
139 | that gets translated by CommonMark into the following HTML:
140 |
141 | ```html
142 |
143 | ```
144 |
145 | Sadly nor CommonMark nor Markdown support figures with captions [(there's an ongoing discussion, though)](http://talk.commonmark.org/t/image-tag-should-expand-to-figure-when-used-with-title/265/5).
146 |
147 | To overcome this limitation xmark uses the following convention
148 |
149 | > Use the 'alt' text as the caption for the figure, and abuse the 'title' text as both the HTML alt and the title.
150 |
151 | So, for instance, the following text:
152 |
153 | ``` markdown
154 | 
158 | ```
159 |
160 | Will be transformed in the following ```
``` and ```
224 | ```
225 |
226 | ## Deviations from tufte-css
227 |
228 | ### Table of Contents
229 |
230 | xmark automatically generates a Table of Contents and places it in a marginnote at the top of the document.
231 |
232 | You can disable this feature by setting the XSLT parameter ```generate-toc``` to ```no``` (see below for an example).
233 |
234 | ### Sections
235 |
236 | xmark does not generate ```def foo(x)
222 | return 3
223 | end