mdx 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/mdx +397 -0
  3. metadata +87 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 29c61ce0d62facb0cdc4df02da59000db7bd5037
4
+ data.tar.gz: c0404c68e87c853465921e59da73057805a52dd3
5
+ SHA512:
6
+ metadata.gz: 38e52277d98ee4767e3c7ec7b7523267574fd647f68073ed86c3be28d2c4b8f0d57975632e1387af49a00ceb7ea4c645527c73b9de42fe6d1218c31f408f8474
7
+ data.tar.gz: f7ae1a4dc56e388663308da84e350b10d9d5369bc7b06265182010e65a2c371884dbd9511dd0dfde39e71ffa07df8db58b8c6930e8085be97c4f98b6459e8074
data/bin/mdx ADDED
@@ -0,0 +1,397 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ require 'rubygems'
4
+ require 'redcarpet'
5
+ require 'rouge'
6
+ require 'rouge/plugins/redcarpet'
7
+ require 'sass'
8
+
9
+ class Title < Redcarpet::Render::XHTML
10
+ include Rouge::Plugins::Redcarpet
11
+
12
+ attr_reader :title
13
+
14
+ def initialize
15
+ @level = 8
16
+ super
17
+ end
18
+
19
+ def header title, level
20
+ if level < @level || !@title
21
+ @title = title
22
+ @level = level
23
+ end
24
+ "<h#{level}>#{title}</h#{level}>"
25
+ end
26
+
27
+ def self.load_templates
28
+ @@templates = {}
29
+
30
+ begin
31
+ io = File.read(__FILE__).force_encoding(Encoding::UTF_8)
32
+ app, data = io.gsub("\r\n", "\n").split(/^__END__$/, 2)
33
+ rescue Errno::ENOENT
34
+ app, data = nil
35
+ end
36
+
37
+ if data
38
+ template = nil
39
+ data.each_line do |line|
40
+ if line =~ /^@@\s*(.*\S)\s*$/
41
+ template = ''
42
+ @@templates[$1.to_sym] = template
43
+ elsif template
44
+ template << line
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ def postprocess doc
51
+ @@templates[:html] % [@title, Sass::Engine.new(@@templates[:style], syntax: :scss, style: :compressed).to_css, doc]
52
+ end
53
+
54
+ load_templates
55
+ end
56
+
57
+ ARGV.each do |filename|
58
+ content = File.read(filename).force_encoding(Encoding::UTF_8)
59
+ md = Redcarpet::Markdown.new(Title.new, fenced_code_blocks: true)
60
+ html = md.render(content)
61
+ File.write("#{File.dirname(filename)}/#{File.basename(filename, '.md')}.html", html)
62
+ end
63
+
64
+ __END__
65
+
66
+ @@html
67
+ <!DOCTYPE html>
68
+ <html>
69
+ <head>
70
+ <meta charset="utf-8"/>
71
+ <title>%s</title>
72
+ <style type="text/css">
73
+ %s
74
+ </style>
75
+ </head>
76
+ <body>
77
+ <div class="content">
78
+ %s
79
+ </div>
80
+ </body>
81
+ </html>
82
+
83
+ @@style
84
+ html
85
+ {
86
+ font-size: 13px;
87
+ font-family: 'Fira Sans', sans-serif;
88
+ }
89
+
90
+ body
91
+ {
92
+ margin: 0px;
93
+ padding: 1em;
94
+ }
95
+
96
+ .content
97
+ {
98
+ margin: 0 auto;
99
+ max-width: 50em;
100
+ }
101
+
102
+ h1
103
+ {
104
+ font-size: 1.5em;
105
+ line-height: 1.2em;
106
+ margin: 0 0 0.5em 0;
107
+ }
108
+
109
+ h2
110
+ {
111
+ font-size: 1.2em;
112
+ line-height: 1.2em;
113
+ margin: 0 0 0.25em 0;
114
+ }
115
+
116
+ h3
117
+ {
118
+ font-size: 1em;
119
+ line-height: 1.2em;
120
+ margin: 0px;
121
+ }
122
+
123
+ p
124
+ {
125
+ font-size: 1em;
126
+ line-height: 1.5em;
127
+ margin: 0 0 0.6em 0;
128
+ text-align: justify;
129
+ }
130
+
131
+ ul
132
+ {
133
+ line-height: 1.5em;
134
+ list-style: disc;
135
+ padding: 0 0 0 1.7em;
136
+ margin: 0 0 0.6em 0;
137
+ }
138
+
139
+ a
140
+ {
141
+ color: #36a;
142
+ text-decoration: none;
143
+ }
144
+
145
+ a:hover
146
+ {
147
+ text-decoration: underline;
148
+ }
149
+
150
+ pre
151
+ {
152
+ font-size: 1em;
153
+ line-height: 1.2em;
154
+ margin: 0 0 0.6em 0;
155
+ padding: 0.25em 0em 0.25em 0.5em;
156
+ border-left: 0.25em solid #999;
157
+ white-space: pre-wrap;
158
+ }
159
+
160
+ code
161
+ {
162
+ font-family: 'Fira Mono', monospace;
163
+ font-weight: normal;
164
+ }
165
+
166
+ pre code
167
+ {
168
+ color: #333;
169
+ }
170
+
171
+ .string, .number, .value
172
+ {
173
+ color: #c12;
174
+ }
175
+
176
+ .keyword
177
+ {
178
+ color: #8a2;
179
+ }
180
+
181
+ .name
182
+ {
183
+ color: #36a;
184
+ }
185
+
186
+ .comment
187
+ {
188
+ color: #999;
189
+ }
190
+
191
+ blockquote
192
+ {
193
+ margin: 0 0 0.6em 0;
194
+ padding: 0.25em 0em 0.25em 0.5em;
195
+ border-left: 0.25em solid #ccc;
196
+ color: #666;
197
+ }
198
+
199
+ hr
200
+ {
201
+ width: 80%;
202
+ margin: 2em auto;
203
+ background: #ccc;
204
+ border: none;
205
+ height: 1px;
206
+ }
207
+
208
+ table
209
+ {
210
+ margin: 0 0 0.6em 0;
211
+ padding: 0;
212
+ width: 100%;
213
+ border-collapse: collapse;
214
+ }
215
+
216
+ table thead
217
+ {
218
+ border-bottom: 1px solid #333;
219
+ }
220
+
221
+ table th, table td
222
+ {
223
+ padding: 0.1em 0.25em;
224
+ text-align: left;
225
+ vertical-align: top;
226
+ }
227
+
228
+ table th
229
+ {
230
+ font-weight: bold;
231
+ }
232
+
233
+ table tbody tr:nth-child(even)
234
+ {
235
+ background: #eee;
236
+ }
237
+
238
+ p:last-child, ul:last-child, li:last-child, pre:last-child, blockquote:last-child, table:last-child
239
+ {
240
+ margin-bottom: 0px;
241
+ }
242
+
243
+ @media print
244
+ {
245
+ a:after {
246
+ content: " (" attr(href) ")";
247
+ }
248
+ }
249
+
250
+ $red: #c12;
251
+ $blue: #09d;
252
+ $green: #8a2;
253
+ $yellow: #fa8;
254
+ $purple: #63a;
255
+ $black: #333;
256
+ $gray: #999;
257
+
258
+ .highlight {
259
+ /* Text.Whitespace: Specially highlighted whitespace */
260
+ .w {}
261
+ /* Error: Lexer errors */
262
+ .err {}
263
+ /* Other: Token for data not matched by a parser (e.g. HTML markup in PHP code) */
264
+ .x {}
265
+ /* Keyword: Any keyword */
266
+ .k {color: $red;}
267
+ /* Keyword.Constant: Keywords that are constants */
268
+ .kc {color: $blue;}
269
+ /* Keyword.Declaration: Keywords used for variable declaration (e.g. var in javascript) */
270
+ .kd {color: $blue;}
271
+ /* Keyword.Namespace: Keywords used for namespace declarations */
272
+ .kn {color: $red;}
273
+ /* Keyword.Pseudo: Keywords that aren't really keywords */
274
+ .kp {color: $red;}
275
+ /* Keyword.Reserved: Keywords which are reserved (such as end in Ruby) */
276
+ .kr {color: $red;}
277
+ /* Keyword.Type: Keywords wich refer to a type id (such as int in C) */
278
+ .kt {color: $blue;}
279
+ /* Name: Variable/function names */
280
+ .n {color: $black;}
281
+ /* Name.Attribute: Attributes (in HTML for instance) */
282
+ .na {color: $green;}
283
+ /* Name.Builtin: Builtin names which are available in the global namespace */
284
+ .nb {color: $black;}
285
+ /* Name.Builtin.Pseudo: Builtin names that are implicit (such as self in Ruby) */
286
+ .bp {color: $black;}
287
+ /* Name.Class: For class declaration */
288
+ .nc {color: $blue;}
289
+ /* Name.Constant: For constants */
290
+ .no {color: $blue;}
291
+ /* Name.Decorator: For decorators in languages such as Python or Java */
292
+ .nd {color: $black;}
293
+ /* Name.Entity: Token for entitites such as &nbsp; in HTML */
294
+ .ni {color: $purple;}
295
+ /* Name.Exception: Exceptions and errors (e.g. ArgumentError in Ruby) */
296
+ .ne {color: $blue;}
297
+ /* Name.Function: Function names */
298
+ .nf {color: $blue;}
299
+ /* Name.Property: Token for properties */
300
+ .py {color: $blue;}
301
+ /* Name.Label: For label names */
302
+ .nl {color: $black;}
303
+ /* Name.Namespace: Token for namespaces */
304
+ .nn {color: $red;}
305
+ /* Name.Other: For other names */
306
+ .nx {color: $black;}
307
+ /* Name.Tag: Tag mainly for markup such as XML or HTML */
308
+ .nt {color: $red;}
309
+ /* Name.Variable: Token for variables */
310
+ .nv {color: $black;}
311
+ /* Name.Variable.Class: Token for class variables (e.g. @@var in Ruby) */
312
+ .vc {color: $black;}
313
+ /* Name.Variable.Global: For global variables (such as $LOAD_PATH in Ruby) */
314
+ .vg {color: $black;}
315
+ /* Name.Variable.Instance: Token for instance variables (such as @var in Ruby) */
316
+ .vi {color: $black;}
317
+ /* Literal: Any literal (if not further defined) */
318
+ .l {color: $purple;}
319
+ /* Literal.Date: Date literals */
320
+ .ld {color: $purple;}
321
+ /* Literal.String: String literals */
322
+ .s {color: $yellow;}
323
+ /* Literal.String.Backtick: String enclosed in backticks */
324
+ .sb {color: $yellow;}
325
+ /* Literal.String.Char: Token type for single characters */
326
+ .sc {color: $yellow;}
327
+ /* Literal.String.Doc: Documentation strings (such as in Python) */
328
+ .sd {color: $yellow;}
329
+ /* Literal.String.Double: Double quoted strings */
330
+ .s2 {color: $yellow;}
331
+ /* Literal.String.Escape: Escaped sequences in strings */
332
+ .se {color: $purple;}
333
+ /* Literal.String.Heredoc: For "heredoc" strings (e.g. in Ruby) */
334
+ .sh {color: $yellow;}
335
+ /* Literal.String.Interpol: For interpoled part in strings (e.g. in Ruby) */
336
+ .si {color: $yellow;}
337
+ /* Literal.String.Other: Token type for any other strings (for example %q{foo} string constructs in Ruby) */
338
+ .sx {color: $yellow;}
339
+ /* Literal.String.Regex: Regular expressions literals */
340
+ .sr {color: $yellow;}
341
+ /* Literal.String.Single: Single quoted strings */
342
+ .s1 {color: $yellow;}
343
+ /* Literal.String.Symbol: Symbols (such as :foo in Ruby) */
344
+ .ss {color: $purple;}
345
+ /* Literal.Number: Any number literal (if not further defined) */
346
+ .m {color: $purple;}
347
+ /* Literal.Number.Float: Float numbers */
348
+ .mf {color: $purple;}
349
+ /* Literal.Number.Hex: Hexadecimal numbers */
350
+ .mh {color: $purple;}
351
+ /* Literal.Number.Integer: Integer literals */
352
+ .mi {color: $purple;}
353
+ /* Literal.Number.Integer.Long: Long interger literals */
354
+ .il {color: $purple;}
355
+ /* Literal.Number.Oct: Octal literals */
356
+ .mo {color: $purple;}
357
+ /* Operator: Operators (commonly +, -, /, *) */
358
+ .o {color: $red;}
359
+ /* Operator.Word: Word operators (e.g. and) */
360
+ .ow {color: $red;}
361
+ /* Punctuation: Punctuation which is not an operator */
362
+ .p {color: $black;}
363
+ /* Comment: Single ligne comments */
364
+ .c {color: $gray;}
365
+ /* Comment.Multiline: Mutliline comments */
366
+ .cm {color: $gray;}
367
+ /* Comment.Preproc: Preprocessor comments such as <% %> in ERb */
368
+ .cp {color: $gray;}
369
+ /* Comment.Single: Comments that end at the end of the line */
370
+ .c1 {color: $gray;}
371
+ /* Comment.Special: Special data in comments such as @license in Javadoc */
372
+ .cs {color: $gray;}
373
+ /* Generic: Unstyled token */
374
+ .g {color: $black;}
375
+ /* Generic.Deleted: Token value as deleted */
376
+ .gd {color: $red;}
377
+ /* Generic.Emph: Token value as emphasized */
378
+ .ge {font-style: italic; color: $black;}
379
+ /* Generic.Error: Token value as an error message */
380
+ .gr {color: $red;}
381
+ /* Generic.Heading: Token value as a headline */
382
+ .gh {font-weight: bold; color: $black;}
383
+ /* Generic.Inserted: Token value as inserted */
384
+ .gi {color: $green;}
385
+ /* Generic.Output: Marked as a program output */
386
+ .go {color: $black;}
387
+ /* Generic.Prompt: Marked as a command prompt */
388
+ .gp {color: $black;}
389
+ /* Generic.Strong: Mark the token value as bold (for rst lexer) */
390
+ .gs {font-weight: bold; color: $black;}
391
+ /* Generic.Subheading: Marked as a subheadline */
392
+ .gu {font-weight: bold; color: $black;}
393
+ /* Generic.Traceback: Mark the token as a part of an error traceback */
394
+ .gt {color: $black;}
395
+ /* Generic.Lineno: Line numbers */
396
+ .gl {color: $gray;}
397
+ }
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mdx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kext
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redcarpet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rouge
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sass
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ description: Convert Markdown files to HTML.
56
+ email: "—"
57
+ executables:
58
+ - mdx
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - bin/mdx
63
+ homepage: http://rubygems.org/gems/mdx
64
+ licenses:
65
+ - Public Domain
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.4.5.1
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: MDX – A Markdown Converter
87
+ test_files: []