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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a779cd45039bccbf2dffd04137a2908e609331484552e4269dd985da9d288532
4
- data.tar.gz: 773b69639460a9d19aeb486a71fad6fd69814216c6c4f65222af643ce0301e37
3
+ metadata.gz: b1f51fa97999eb183b22c7944e668e1adca2bcac6cf75ab8020971f04381db96
4
+ data.tar.gz: 0a282bf3b6c58ad14286111c6e292ad9018af27fd2da85132e3fe2351919e6d0
5
5
  SHA512:
6
- metadata.gz: 28f22a19ba9fcb37196fb591c72e4a2bb3314b1616972d2857bcc21fb26514b39cc1562b1d718410c08f7354549f921aaaa551010488dd5990638e1388a2d4fa
7
- data.tar.gz: afeed9b58bcf5d372afc5511a583835d4ebcd02b5f2a5608e1de5c8719e9188a0bccc32dc244fb18004401c3233d367d705d853159d197399053adcc38c567f4
6
+ metadata.gz: c4f26691d74475afdc40602edc5bc533725a7060109cea4ffc22b00889fb2d0411dfe1c28187d234f0701f6cda13d459dcf3b830b8d1e8df380fefcf51439319
7
+ data.tar.gz: 0f381f92ba1434155a9b7d87323ee557fd2a42cd2978b2e42dce88b06002991f17731702c68a23b151c38598e79fe6ae4e6bc74387626b8b62427a49af6fbc94
@@ -33,7 +33,7 @@ PLATFORMS
33
33
  DEPENDENCIES
34
34
  bundler (~> 2.0)
35
35
  markie!
36
- pry
36
+ pry (~> 0.12)
37
37
  rake (~> 10.0)
38
38
  rspec (~> 3.0)
39
39
 
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 in Ruby
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`
@@ -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
@@ -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
- if tokens[0].type == :text
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
@@ -1,3 +1,3 @@
1
1
  module Markie
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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-07 00:00:00.000000000 Z
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