daimon-markdown 0.2.4 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aff20c01e34584946a115276b997d78505820a88
4
- data.tar.gz: c7d557edcc62ec6ebde33bfa669be2033e0c9053
3
+ metadata.gz: b8d9ae79f89262e2e5b173fd510137589bc6356a
4
+ data.tar.gz: b8e4072e934cac8da673c2efd259abc3435fba79
5
5
  SHA512:
6
- metadata.gz: 2f1e21e1cd6ebadef92dcfdfb11b1baefb92da4c8e20208ae74f90e801722dbf771a4ee6332063e24559adfc083284595ccc6a139c3298d7319e5b2f33c8e381
7
- data.tar.gz: 8fbe830c68dfd476b6f8e9d1479a7c3eef613e9743fc82f117553e63dc83795f9fa2c518835f4dcb6432b55da1a20531b01f209c5f577c3b8d2a8a003bc029db
6
+ metadata.gz: f56abca8ff5b504bcdf82e984a3b86efc7df6fd065eaa63e49b7b7e894670c3bf7f456321d64f8bdbc2cd6838fd59c10ec0973e82970a9eeabca4a4ef463acbd
7
+ data.tar.gz: b09300574c8c6475eda6c85ef1c8d2a9620743fa0be147e21fb08a2eaef5c527bf0577b9def206ec0d832e280a8bf27ed2b28b89fd368263fc6dbf3f9079ddcb
@@ -9,11 +9,18 @@ module Daimon
9
9
  next if node.parent.name == "code" # skip code block
10
10
  result[:plugins] = []
11
11
  node.to_s.scan(/{{(.+?)}}/m) do |str|
12
- parser = Daimon::Markdown::Parser.new(str[0])
13
- parser.parse
14
- plugin_class = Daimon::Markdown::Plugin.lookup(parser.name)
15
- plugin = plugin_class.new(doc, node, result, context)
16
- plugin.call(*parser.args)
12
+ begin
13
+ parser = Daimon::Markdown::Parser.new(str[0])
14
+ parser.parse
15
+ plugin_class = Daimon::Markdown::Plugin.lookup(parser.name)
16
+ plugin = plugin_class.new(doc, node, result, context)
17
+ plugin.call(*parser.args)
18
+ rescue Daimon::Markdown::Parser::Error => ex
19
+ message = "#{node} (#{ex.class}: #{ex.message})"
20
+ node.replace(message)
21
+ rescue Daimon::Markdown::Plugin::UnknownPluginError => ex
22
+ node.replace(ex.message)
23
+ end
17
24
  end
18
25
  unless result[:plugins].empty?
19
26
  scanner = StringScanner.new(node.to_s)
@@ -4,6 +4,9 @@ module Daimon
4
4
  module Markdown
5
5
  class Parser < Ripper
6
6
 
7
+ class Error < StandardError
8
+ end
9
+
7
10
  KEYWORDS = {
8
11
  "nil" => nil,
9
12
  "true" => true,
@@ -83,6 +86,16 @@ module Daimon
83
86
  @arrays[@level - 1] << @arrays[@level]
84
87
  @level -= 1
85
88
  end
89
+
90
+ def on_parse_error(message)
91
+ compile_error(message)
92
+ end
93
+
94
+ private
95
+
96
+ def compile_error(message)
97
+ raise Error, message
98
+ end
86
99
  end
87
100
  end
88
101
  end
@@ -4,9 +4,14 @@ module Daimon
4
4
 
5
5
  PLUGIN_REGISTRY = {}
6
6
 
7
+ class UnknownPluginError < StandardError
8
+ end
9
+
7
10
  class << self
8
11
  def lookup(name)
9
12
  PLUGIN_REGISTRY.fetch(name)
13
+ rescue KeyError
14
+ raise UnknownPluginError, "Unknown plugin: #{name}"
10
15
  end
11
16
 
12
17
  def register(name, klass)
@@ -1,5 +1,5 @@
1
1
  module Daimon
2
2
  module Markdown
3
- VERSION = "0.2.4"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daimon-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - daimon developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-27 00:00:00.000000000 Z
11
+ date: 2016-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html-pipeline