1 | # rebber [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status]
|
2 |
|
3 |
|
4 | **rebber** is a LaTeX stringifier for [remark][]
|
5 |
|
6 | ## Installation
|
7 |
|
8 | [npm][]:
|
9 |
|
10 | ```bash
|
11 | npm install rebber
|
12 | ```
|
13 |
|
14 | ## Usage
|
15 |
|
16 | ```javascript
|
17 | const unified = require('unified')
|
18 | const remarkParser = require('remark-parse')
|
19 | const rebber = require('rebber')
|
20 |
|
21 | const {contents} = unified()
|
22 | .use(remarkParser)
|
23 | .use(rebber)
|
24 | .processSync('### foo')
|
25 |
|
26 | console.log(contents);
|
27 | ```
|
28 |
|
29 | Yields:
|
30 |
|
31 | ```latex
|
32 | \section{foo}
|
33 | ```
|
34 |
|
35 | ## API
|
36 |
|
37 | ### `toLaTeX(node[, options])`
|
38 |
|
39 | Stringify the given [MDAST node][mdast].
|
40 |
|
41 |
|
42 | #### `options.overrides`
|
43 |
|
44 | Overrides are named that way because they can override any MDAST node type to latex stringifier. Their other use is to use custom latex stringifier for custom MDAST node type.
|
45 |
|
46 | Examples:
|
47 |
|
48 | ```js
|
49 | const {contents} = unified()
|
50 | .use(remarkParser)
|
51 | .use(remarkFoobarElementsParser) // creates MDAST nodes of type 'foobar'
|
52 | .use(rebber, {
|
53 | overrides: {
|
54 | // override rebber's method to turn MDAST link nodes into latex
|
55 | link: require('./your-own-link-latexifier')
|
56 | // tell rebber what to use to turn MDAST foobar nodes into latex
|
57 | foobar: require('./your-foobar-latexifier')
|
58 | }
|
59 | })
|
60 |
|
61 | ```
|
62 |
|
63 | #### `options.<mdastNodeType>`
|
64 |
|
65 | [MDAST nodes][mdast] are stringified to LaTeX using sensible default LaTeX commands. However, you can customize most of the LaTeX command corresponding to MDAST nodes. Here are documented the function signatures of these customizable commands. Note that the keys of the `options` object are named after the corresponding MDAST node type.
|
66 |
|
67 | For example, by default, `![](/foo.png)` will get compiled to `\includegraphics{/foo.png}`.
|
68 |
|
69 | Setting
|
70 | ```js
|
71 | options.image = (node) => `[inserted image located at "${node.url}"]`
|
72 | ```
|
73 |
|
74 | will stringify our example Markdown to `[inserted image located at "/foo.png"]` instead of `\includegraphics{/foo.png}`.
|
75 |
|
76 | ###### `options.blockquote`
|
77 |
|
78 | (text) => ``,
|
79 |
|
80 | ###### `options.break`
|
81 |
|
82 | () => ``,
|
83 |
|
84 | ###### `options.code`
|
85 |
|
86 | (textCode, lang) => ``,
|
87 |
|
88 | ###### `options.definition`
|
89 |
|
90 | (options, identifier, url, title) => ``,
|
91 |
|
92 | ###### `options.footnote`
|
93 |
|
94 | (identifier, text, protect) => ``,
|
95 |
|
96 | ###### `options.footnoteDefinition`
|
97 |
|
98 | (identifier, text) => ``,
|
99 |
|
100 | ###### `options.footnoteReference`
|
101 |
|
102 | (identifier) => ``,
|
103 |
|
104 | ###### `options.headings`
|
105 |
|
106 | [
|
107 | (text) => ``, // level 1 heading
|
108 | (text) => ``, // level 2 heading
|
109 | (text) => ``, // level 3 heading
|
110 | (text) => ``, // level 4 heading
|
111 | (text) => ``, // level 5 heading
|
112 | (text) => ``, // level 6 heading
|
113 | (text) => ``, // level 7 heading
|
114 | ],
|
115 |
|
116 | ###### `options.image`
|
117 |
|
118 | (node) => ``,
|
119 |
|
120 | ###### `options.link`
|
121 |
|
122 | (displayText, url, title) => ``,
|
123 |
|
124 | ###### `options.linkReference`
|
125 |
|
126 | (reference, content) => ``,
|
127 |
|
128 | ###### `options.list`
|
129 |
|
130 | (content, isOrdered) => ``,
|
131 |
|
132 | ###### `options.listItem`
|
133 |
|
134 | (content) => ``,
|
135 |
|
136 | ###### `options.text`
|
137 |
|
138 | (text) => ``,
|
139 |
|
140 | ###### `options.thematicBreak`
|
141 |
|
142 | () => ``,
|
143 |
|
144 | ###### `options.table`
|
145 |
|
146 | (ctx, node) => ``,
|
147 |
|
148 | To ensure a flexible rendering, `longtabu` environment is used by default.
|
149 | Table stringification can be configured with some advanced options:
|
150 |
|
151 | ###### `options.spreadCell`
|
152 |
|
153 | ` spread 0pt `
|
154 |
|
155 | Customize cells spacing (usually done using the `spread` command).
|
156 | Common commands are ` spread <dimension> ` (add `<dimension>` as spacing ) or ` to <dimension> ` (fix the overall width of table).
|
157 | Default value is ` spread 0pt ` (natural spacing).
|
158 |
|
159 | ###### `options.firstLineRowFont`
|
160 |
|
161 | `'\\rowfont[c]{\\bfseries}'`
|
162 |
|
163 | Customize the first line font (this is useful when your tables always have a header as first line).
|
164 | Default value is `'\\rowfont[c]{\\bfseries}'` (bold, center aligned).
|
165 |
|
166 | ###### `options.defaultOtherLineRowFont`
|
167 |
|
168 | `'\\rowfont[l]{}'`
|
169 |
|
170 | Customize table font for all lines except the first.
|
171 | Default value is `'\\rowfont[l]{}'` (normal font, left aligned).
|
172 |
|
173 | ###### `options.headerParse: (tableRows) => ''`
|
174 |
|
175 | (tableRows) => ''
|
176 |
|
177 | Cunction that computes the "latex header" part of the table environment, this generates strings such as `|c|c|r|`.
|
178 | It gets an array of all the `tableRow` [mdast] nodes for the table as argument.
|
179 | Default function extracts the number of columns for each row and uses the `X[-1]` handler ("find the best available width").
|
180 | The result for a 3 column-table is `|X[-1]|X[-1]|X[-1]|`.
|
181 |
|
182 |
|
183 | ## Related
|
184 |
|
185 | * [`rebber-plugins`][rebber-plugins]
|
186 | - A collection of rebber plugins able to stringify custom Remark node types.
|
187 |
|
188 | ## License
|
189 |
|
190 | [MIT][license] © [Zeste de Savoir][zds]
|
191 |
|
192 |
|
193 |
|
194 | [build-badge]: https://img.shields.io/travis/zestedesavoir/zmarkdown.svg
|
195 |
|
196 | [build-status]: https://travis-ci.org/zestedesavoir/zmarkdown
|
197 |
|
198 | [coverage-badge]: https://img.shields.io/coveralls/zestedesavoir/zmarkdown.svg
|
199 |
|
200 | [coverage-status]: https://coveralls.io/github/zestedesavoir/zmarkdown
|
201 |
|
202 | [license]: https://github.com/zestedesavoir/zmarkdown/blob/master/packages/rebber/LICENSE-MIT
|
203 |
|
204 | [rebber-plugins]: https://github.com/zestedesavoir/zmarkdown/blob/master/packages/rebber-plugins
|
205 |
|
206 | [zds]: https://zestedesavoir.com
|
207 |
|
208 | [npm]: https://www.npmjs.com/package/rebber
|
209 |
|
210 | [mdast]: https://github.com/syntax-tree/mdast/blob/master/readme.md
|
211 |
|
212 | [remark]: https://github.com/remarkjs/remark
|