markly 0.6.1 → 0.8.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 (52) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/conduct.md +133 -0
  4. data/ext/markly/arena.c +9 -8
  5. data/ext/markly/autolink.c +217 -134
  6. data/ext/markly/blocks.c +40 -4
  7. data/ext/markly/cmark-gfm-core-extensions.h +11 -11
  8. data/ext/markly/cmark-gfm-extension_api.h +1 -0
  9. data/ext/markly/cmark-gfm.h +18 -2
  10. data/ext/markly/cmark-gfm_version.h +2 -2
  11. data/ext/markly/cmark.c +3 -3
  12. data/ext/markly/commonmark.c +33 -38
  13. data/ext/markly/ext_scanners.c +360 -640
  14. data/ext/markly/extconf.rb +8 -1
  15. data/ext/markly/footnotes.c +23 -0
  16. data/ext/markly/footnotes.h +2 -0
  17. data/ext/markly/html.c +60 -23
  18. data/ext/markly/inlines.c +216 -61
  19. data/ext/markly/latex.c +6 -4
  20. data/ext/markly/man.c +7 -11
  21. data/ext/markly/map.c +11 -4
  22. data/ext/markly/map.h +5 -2
  23. data/ext/markly/markly.c +582 -586
  24. data/ext/markly/markly.h +1 -1
  25. data/ext/markly/node.c +76 -10
  26. data/ext/markly/node.h +49 -1
  27. data/ext/markly/parser.h +1 -0
  28. data/ext/markly/plaintext.c +12 -29
  29. data/ext/markly/references.c +1 -0
  30. data/ext/markly/render.c +15 -7
  31. data/ext/markly/scanners.c +13916 -20242
  32. data/ext/markly/scanners.h +8 -0
  33. data/ext/markly/scanners.re +47 -8
  34. data/ext/markly/strikethrough.c +1 -1
  35. data/ext/markly/table.c +143 -74
  36. data/ext/markly/xml.c +2 -1
  37. data/lib/markly/flags.rb +16 -0
  38. data/lib/markly/node/inspect.rb +59 -53
  39. data/lib/markly/node.rb +125 -58
  40. data/lib/markly/renderer/generic.rb +136 -0
  41. data/lib/markly/renderer/html.rb +301 -0
  42. data/lib/markly/version.rb +7 -1
  43. data/lib/markly.rb +38 -32
  44. data/license.md +39 -0
  45. data/readme.md +36 -0
  46. data.tar.gz.sig +0 -0
  47. metadata +63 -31
  48. metadata.gz.sig +0 -0
  49. data/bin/markly +0 -94
  50. data/lib/markly/markly.so +0 -0
  51. data/lib/markly/renderer/html_renderer.rb +0 -281
  52. data/lib/markly/renderer.rb +0 -133
@@ -1,133 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'set'
4
- require 'stringio'
5
-
6
- module Markly
7
- class Renderer
8
- attr_accessor :in_tight, :warnings, :in_plain
9
- def initialize(flags: DEFAULT, extensions: [])
10
- @flags = flags
11
- @stream = StringIO.new(+'')
12
- @need_blocksep = false
13
- @warnings = Set.new
14
- @in_tight = false
15
- @in_plain = false
16
- @tagfilter = extensions.include?(:tagfilter)
17
- end
18
-
19
- def out(*args)
20
- args.each do |arg|
21
- if arg == :children
22
- @node.each { |child| out(child) }
23
- elsif arg.is_a?(Array)
24
- arg.each { |x| render(x) }
25
- elsif arg.is_a?(Node)
26
- render(arg)
27
- else
28
- @stream.write(arg)
29
- end
30
- end
31
- end
32
-
33
- def render(node)
34
- @node = node
35
- if node.type == :document
36
- document(node)
37
- @stream.string
38
- elsif @in_plain && node.type != :text && node.type != :softbreak
39
- node.each { |child| render(child) }
40
- else
41
- begin
42
- send(node.type, node)
43
- rescue NoMethodError => e
44
- @warnings.add("WARNING: #{node.type} not implemented.")
45
- raise e
46
- end
47
- end
48
- end
49
-
50
- def document(_node)
51
- out(:children)
52
- end
53
-
54
- def code_block(node)
55
- code_block(node)
56
- end
57
-
58
- def reference_def(_node); end
59
-
60
- def cr
61
- return if @stream.string.empty? || @stream.string[-1] == "\n"
62
-
63
- out("\n")
64
- end
65
-
66
- def blocksep
67
- out("\n")
68
- end
69
-
70
- def containersep
71
- cr unless @in_tight
72
- end
73
-
74
- def block
75
- cr
76
- yield
77
- cr
78
- end
79
-
80
- def container(starter, ender)
81
- out(starter)
82
- yield
83
- out(ender)
84
- end
85
-
86
- def plain
87
- old_in_plain = @in_plain
88
- @in_plain = true
89
- yield
90
- @in_plain = old_in_plain
91
- end
92
-
93
- private
94
-
95
- def escape_href(str)
96
- @node.html_escape_href(str)
97
- end
98
-
99
- def escape_html(str)
100
- @node.html_escape_html(str)
101
- end
102
-
103
- def tagfilter(str)
104
- if @tagfilter
105
- str.gsub(
106
- %r{
107
- <
108
- (
109
- title|textarea|style|xmp|iframe|
110
- noembed|noframes|script|plaintext
111
- )
112
- (?=\s|>|/>)
113
- }xi,
114
- '&lt;\1'
115
- )
116
- else
117
- str
118
- end
119
- end
120
-
121
- def source_position(node)
122
- return '' unless flag_enabled?(SOURCE_POSITION)
123
-
124
- s = node.source_position
125
- " data-sourcepos=\"#{s[:start_line]}:#{s[:start_column]}-" \
126
- "#{s[:end_line]}:#{s[:end_column]}\""
127
- end
128
-
129
- def flag_enabled?(flag)
130
- (@flags & flag) != 0
131
- end
132
- end
133
- end