markie 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/markie.rb +13 -0
- data/lib/markie/generator.rb +45 -0
- data/lib/markie/parser.rb +1 -2
- data/lib/markie/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1f51fa97999eb183b22c7944e668e1adca2bcac6cf75ab8020971f04381db96
|
4
|
+
data.tar.gz: 0a282bf3b6c58ad14286111c6e292ad9018af27fd2da85132e3fe2351919e6d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4f26691d74475afdc40602edc5bc533725a7060109cea4ffc22b00889fb2d0411dfe1c28187d234f0701f6cda13d459dcf3b830b8d1e8df380fefcf51439319
|
7
|
+
data.tar.gz: 0f381f92ba1434155a9b7d87323ee557fd2a42cd2978b2e42dce88b06002991f17731702c68a23b151c38598e79fe6ae4e6bc74387626b8b62427a49af6fbc94
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Markie <img src="https://i.postimg.cc/wxXhdwZr/markie-2.jpg" alt="markie_logo" width="100" align="right"/>
|
2
2
|
|
3
|
-
Proof-of-concept Markdown to HTML compiler
|
3
|
+
Proof-of-concept Markdown to HTML compiler Ruby gem. <img src="https://badge.fury.io/rb/markie.svg" alt="markie_gem" width="100" align="right"/>
|
4
4
|
|
5
5
|
|
6
6
|
## Grammar v.`6c20d2a`
|
data/lib/markie.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
|
+
require "markie/generator"
|
1
2
|
require "markie/node"
|
2
3
|
require "markie/parser"
|
3
4
|
require "markie/rule"
|
4
5
|
require "markie/token"
|
5
6
|
require "markie/tokenizer"
|
6
7
|
require "markie/version"
|
8
|
+
|
9
|
+
module Markie
|
10
|
+
class << self
|
11
|
+
def to_html(markdown)
|
12
|
+
Generator.generate(
|
13
|
+
Parser.parse(
|
14
|
+
Tokenizer.tokenize(markdown)
|
15
|
+
)
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Markie
|
2
|
+
class Generator
|
3
|
+
class << self
|
4
|
+
def generate(ast)
|
5
|
+
body(ast)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def body(node)
|
11
|
+
content = node.children.map { |child|
|
12
|
+
paragraph(child)
|
13
|
+
}.join("")
|
14
|
+
|
15
|
+
"<body>#{content}</body>"
|
16
|
+
end
|
17
|
+
|
18
|
+
def paragraph(node)
|
19
|
+
content = node.children.map { |child|
|
20
|
+
if child.type == :text
|
21
|
+
text(child)
|
22
|
+
elsif child.type == :link
|
23
|
+
link(child)
|
24
|
+
elsif child.type == :emphasis
|
25
|
+
emphasis(child)
|
26
|
+
end
|
27
|
+
}.join("")
|
28
|
+
|
29
|
+
"<p>#{content}</p>"
|
30
|
+
end
|
31
|
+
|
32
|
+
def text(node)
|
33
|
+
node.value
|
34
|
+
end
|
35
|
+
|
36
|
+
def link(node)
|
37
|
+
"<a href=\"#{node.value}\">#{text(node.children[0])}</a>"
|
38
|
+
end
|
39
|
+
|
40
|
+
def emphasis(node)
|
41
|
+
"<em>#{node.value}</em>"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/markie/parser.rb
CHANGED
@@ -16,9 +16,8 @@ module Markie
|
|
16
16
|
def parse_paragraph(tokens, children = [])
|
17
17
|
if tokens[0].type == :eof
|
18
18
|
return Node.new(type: :paragraph, token_count: children.map(&:token_count).sum, children: children)
|
19
|
-
end
|
20
19
|
|
21
|
-
|
20
|
+
elsif tokens[0].type == :text
|
22
21
|
next_child = Node.new(type: :text, token_count: 1, value: tokens[0].value)
|
23
22
|
|
24
23
|
elsif tokens[0].type == :underscore && tokens[1].type == :text && tokens[2].type == :underscore
|
data/lib/markie/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thomascountz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- bin/console
|
88
88
|
- bin/setup
|
89
89
|
- lib/markie.rb
|
90
|
+
- lib/markie/generator.rb
|
90
91
|
- lib/markie/node.rb
|
91
92
|
- lib/markie/parser.rb
|
92
93
|
- lib/markie/rule.rb
|