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 | ## Related
|
145 |
|
146 | * [`rebber-plugins`][rebber-plugins]
|
147 | — A collection of rebber plugins able to stringify custom Remark node types.
|
148 |
|
149 | ## License
|
150 |
|
151 | [MIT][license] © [Zeste de Savoir][zds]
|
152 |
|
153 |
|
154 |
|
155 | [build-badge]: https://img.shields.io/travis/zestedesavoir/zmarkdown.svg
|
156 |
|
157 | [build-status]: https://travis-ci.org/zestedesavoir/zmarkdown
|
158 |
|
159 | [coverage-badge]: https://img.shields.io/coveralls/zestedesavoir/zmarkdown.svg
|
160 |
|
161 | [coverage-status]: https://coveralls.io/github/zestedesavoir/zmarkdown
|
162 |
|
163 | [license]: https://github.com/zestedesavoir/zmarkdown/blob/master/packages/rebber/LICENSE-MIT
|
164 |
|
165 | [rebber-plugins]: https://github.com/zestedesavoir/zmarkdown/blob/master/packages/rebber-plugins
|
166 |
|
167 | [zds]: https://zestedesavoir.com
|
168 |
|
169 | [npm]: https://www.npmjs.com/package/rebber
|
170 |
|
171 | [mdast]: https://github.com/syntax-tree/mdast/blob/master/readme.md
|
172 |
|
173 | [remark]: https://github.com/remarkjs/remark
|