md2key 0.1.2 → 0.2.0

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
  SHA1:
3
- metadata.gz: 715e0b41ecbfdbb4b7bd47471b3869361fdf12a4
4
- data.tar.gz: 4aa12b0da58a5571dba5bbf57844d5b6b536274c
3
+ metadata.gz: 9344258d896f70f623b6297cd04a23d5f89dfd4c
4
+ data.tar.gz: 21aecf4aee086196aac28d1ddb49b519e86d8375
5
5
  SHA512:
6
- metadata.gz: 0b8459ae62e7adeaf6f57757d0d1420ac18106a0d13320ef581d454d16cdb767c547ae22b1d7f49b5bf9c4f2664c78d2f14d43877b2bf735ac0d823d7a9d7d07
7
- data.tar.gz: 00219c993468952728073684d4051b2d41eae58594255fba50500ba17da89234debdf49fb068a38f3d468a54cb9ec009edeff2ef3e273eb2e5feaa8c62a7280e
6
+ metadata.gz: 0e99d47cfe441d711a6a3bf5de5214df354b3b1a291a902679acfb2ada90ecf59613fc72dac76588a16dded595bf36a2239c82f41f2719d3ad9e5dd38737b26b
7
+ data.tar.gz: cfda1467a4bd799182cc7955420512fbe2d457716227fc52b740ce12fe5459ae12cc4e5cc9da3f4ca73a1d0d9dae8211e1d363683461d4a3a598767ba1e5b0f9
data/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # v0.2.0
2
+
3
+ - Use redcarpet as markdown parser
4
+ - Support `*` list
5
+
6
+ # v0.1.2
7
+
8
+ - Temporarily support skipping `---`
9
+ - Still expecting users to write a format like Deckset
10
+ - https://github.com/k0kubun/md2key/pull/2
11
+
12
+ # v0.1.1
13
+
14
+ - Fix strange indentation
15
+ - https://github.com/k0kubun/md2key/issues/1
16
+
17
+ # v0.1.0
18
+
19
+ - Initial release
20
+ - Parse only `#`, `-` and `---`
@@ -1,37 +1,62 @@
1
+ require 'redcarpet'
2
+ require 'oga'
3
+
4
+ # Parse markdown, generate AST and convert it to slides.
5
+ # This is created to be compatible with Deckset.
6
+ # See: http://www.decksetapp.com/cheatsheet/
1
7
  module Md2key
2
8
  class Markdown
3
9
  def initialize(path)
4
- @markdown = File.read(path)
10
+ markdown = File.read(path)
11
+ xhtml = to_xhtml(markdown)
12
+ @ast = Oga.parse_xml(xhtml)
5
13
  end
6
14
 
7
15
  def slides
8
- @slides ||= parse_markdown
16
+ @slides ||= generate_slides
9
17
  end
10
18
 
11
19
  private
12
20
 
13
- def parse_markdown
21
+ def generate_slides
14
22
  slides = []
15
23
  slide = Slide.new
16
24
 
17
- @markdown.each_line do |line|
18
- line = line.strip
19
- case line
20
- when /^--+$/
21
- # noop
22
- when /^# *(.+)$/
25
+ @ast.children.each do |node|
26
+ next unless node.is_a?(Oga::XML::Element)
27
+
28
+ case node.name
29
+ when /^h[1-9]$/
30
+ # New slide by header. You can skip to write `---`.
31
+ # This feature will be removed in the future to provide
32
+ # more compatibility with Deckset.
33
+ # See: https://github.com/k0kubun/md2key/pull/2
34
+ if slides.any?
35
+ slide = Slide.new
36
+ end
37
+
23
38
  slides << slide
24
- slide = Slide.new
25
- slide.title = $1
26
- when /^- *(.+)$/
27
- slide.lines << $1
28
- else
29
- slide.lines << line unless line.empty?
39
+ slide.title = node.text
40
+ when 'ul'
41
+ node.children.each do |child_node|
42
+ next unless child_node.is_a?(Oga::XML::Element)
43
+ next if child_node.name != 'li'
44
+
45
+ # TODO: implement nested list
46
+ slide.lines << child_node.inner_text.strip
47
+ end
48
+ when 'p'
49
+ slide.lines << node.text
50
+ when 'hr'
51
+ # noop
30
52
  end
31
53
  end
32
- slides << slide
33
- slides.shift unless slides.empty?
34
54
  slides
35
55
  end
56
+
57
+ def to_xhtml(markdown)
58
+ redcarpet = Redcarpet::Markdown.new(Redcarpet::Render::XHTML)
59
+ redcarpet.render(markdown)
60
+ end
36
61
  end
37
62
  end
@@ -1,3 +1,3 @@
1
1
  module Md2key
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
data/md2key.gemspec CHANGED
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_dependency "thor", "~> 0.19"
21
21
  spec.add_dependency "unindent", "~> 1.0"
22
+ spec.add_dependency "redcarpet", "~> 3.3"
23
+ spec.add_dependency "oga", "~> 1.2"
22
24
  spec.add_development_dependency "bundler", "~> 1.10"
23
25
  spec.add_development_dependency "rake", "~> 10.0"
24
26
  spec.add_development_dependency "pry"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: md2key
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: redcarpet
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: oga
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: bundler
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -89,7 +117,7 @@ extensions: []
89
117
  extra_rdoc_files: []
90
118
  files:
91
119
  - ".gitignore"
92
- - ".travis.yml"
120
+ - CHANGELOG.md
93
121
  - Gemfile
94
122
  - README.md
95
123
  - Rakefile
data/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.2
4
- before_install: gem install bundler -v 1.10.6