beardown 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ef27cfa59523daac166770eacf230170e0ec635835498b9079a2d23acc327419
4
+ data.tar.gz: 2e98a722ea7c2a6143e7270963b1ec64ad5bbb2f9092213605e997b58802ba4f
5
+ SHA512:
6
+ metadata.gz: f98f9e4f4020980705900f8b78b1172f71f8703770f2b56bc0277c35256aa8e914c194b2f1f7e35333fcf625ef32014b2b19eba176b5e0fd75c90707ed28317b
7
+ data.tar.gz: 297712a2bbb316d125b7570525af8efd900b9255cd747e9ef39e31131b56104a655dda3f0c6b47b3bebaf48bd5c0ea658dc728d6513f30ba383a16009dc9f1d8
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # add
14
+ .DS_Store
15
+ /bin/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in beardown.gemspec
6
+ gemspec
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ beardown (0.1.3)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.11.3)
10
+ rake (10.5.0)
11
+ rouge (3.1.1)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ beardown!
18
+ bundler (~> 1.16)
19
+ minitest (~> 5.0)
20
+ rake (~> 10.0)
21
+ rouge (~> 3.1.1)
22
+
23
+ BUNDLED WITH
24
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 wuusn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # Beardown
2
+
3
+ A html convertor for [Bear](http://www.bear-writer.com) App's bearnote - [Polar Bear markup language](http://www.bear-writer.com/faq/Markup%20:%20Markdown/Polar%20Bear%20markup%20language/) inspired by CommonMark, and this convertor used by [Miyano](https://github.com/wuusn/miyano)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'beardown'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install beardown
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require "beardown"
25
+
26
+ text = File.read "text.txt"
27
+ note = Beardown.new text
28
+
29
+ note.html
30
+ note.title
31
+ note.content
32
+ note.summary
33
+ note.tags
34
+
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wuusn/beardown.
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,36 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "beardown/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "beardown"
8
+ spec.version = Beardown::VERSION
9
+ spec.authors = ["wuusn"]
10
+ spec.email = ["wuusin@gmail.com"]
11
+
12
+ spec.summary = %q{A html convertor for Bear App's bearnote - Polar Bear markup language.}
13
+ spec.homepage = "https://github.com/wuusn/beardown"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.16"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "minitest", "~> 5.0"
35
+ spec.add_development_dependency "rouge", "~> 3.1.1"
36
+ end
@@ -0,0 +1,25 @@
1
+ require "beardown/version"
2
+ require "beardown/document"
3
+ require "beardown/blocks/head"
4
+ require "beardown/blocks/line_separator"
5
+ require "beardown/blocks/list_unordered"
6
+ require "beardown/blocks/list_ordered"
7
+ require "beardown/blocks/quote"
8
+ require "beardown/blocks/list_todo"
9
+ require "beardown/blocks/codeblock"
10
+ require "beardown/blocks/asset"
11
+ require "beardown/blocks/blankline"
12
+ require "beardown/blocks/p"
13
+ require "beardown/spans/bold_italic_underline_strike"
14
+ require "beardown/spans/linkurl"
15
+ require "beardown/spans/linkpost"
16
+ require "beardown/spans/mark"
17
+ require "beardown/spans/hashtag"
18
+ require "beardown/spans/codespan"
19
+
20
+ module Beardown
21
+ # Your code goes here...
22
+ def self.new(text)
23
+ Document.new(text)
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ module Beardown
2
+ class Document
3
+ REGEXP_ASSET = /^\[assets\/(.+)\]\n?/
4
+
5
+ def scan_asset(s)
6
+ filename = s[1]
7
+ convert_asset filename
8
+ end
9
+
10
+ def convert_asset(filename)
11
+ if is_img? filename
12
+ return %(<p><img src="assets/#{filename}"></p>\n)
13
+ else
14
+ return %(<p><a href="assets/#{filename}">#{filename}</a></p>\n)
15
+ end
16
+ end
17
+
18
+ def is_img?(filename)
19
+ ext = File.extname filename
20
+ case ext.downcase
21
+ when ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".ico", ".tiff", ".svg", ".apng"
22
+ return true
23
+ else
24
+ return false
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ module Beardown
2
+ class Document
3
+ REGEXP_BLANKLINE = /^\s*?\n/
4
+
5
+ def scan_blankline(s)
6
+ convert_blankline
7
+ end
8
+
9
+ def convert_blankline
10
+ "<br>\n"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,84 @@
1
+ require "rouge"
2
+ module Beardown
3
+ class Document
4
+ REGEXP_CODEBLOCK = /^```(.*)\n((.*\n)*?)^```\n?/
5
+
6
+ def scan_codeblock(s)
7
+ code = $code_map[s[1].strip.downcase]
8
+ content = s[2]
9
+ convert_codeblock(content, code)
10
+ end
11
+
12
+ def convert_codeblock(content, code)
13
+ lexer_class = case code
14
+ when nil
15
+ Rouge::Lexer.guess_by_source content
16
+ #Rouge::Lexers::PlainText
17
+ else
18
+ Rouge::Lexers.const_get code
19
+ end
20
+ lexer = lexer_class.new
21
+ formatter = Rouge::Formatters::HTML.new
22
+ %(<pre><code class="code-multiline highlight">#{formatter.format(lexer.lex(content))}</code></pre>\n)
23
+ end
24
+
25
+ $code_map = {
26
+ # bear supported
27
+ "apache"=>"Apache",
28
+ "c"=>"C", "c++"=>"Cpp", "cpp"=>"Cpp",
29
+ "c#"=>"CSharp", "csharp"=>"CSharp",
30
+ "coffee"=>"Coffeescript", "coffeescript"=>"Coffeescript",
31
+ "css"=>"CSS", "html"=>"HTML", "php"=>"PHP",
32
+ "go"=>"Go", "golang"=>"Go",
33
+ "java"=>"Java", "js"=>"Javascript", "javascript"=>"Javascript",
34
+ "json"=>"JSON",
35
+ "lua"=>"Lua",
36
+ "mat"=>"Matlab", "matlab"=>"Matlab",
37
+ "objective-c"=>"ObjectiveC", "objc"=>"ObjectiveC",
38
+ "perl"=>"Perl",
39
+ "py"=>"Python", "python"=>"Python",
40
+ "r"=>"R", "rb"=>"Ruby", "ruby"=>"Ruby",
41
+ "sc"=>"Scala", "scala"=>"Scala",
42
+ "scss"=>"Scss", "sass"=>"Sass",
43
+ "shell"=>"Shell", "sh"=>"Shell",
44
+ "sql"=>"SQL", "swift"=>"Swift",
45
+ "latex"=>"TeX", "tex"=>"TeX",
46
+ "xml"=>"XML",
47
+
48
+ # rouge supported but bear not
49
+ "abap"=>"ABAP", "fsharp"=>"FSharp", "sasscommon"=>"SassCommon",
50
+ "actionscript"=>"Actionscript", "gherkin"=>"Gherkin", "make"=>"Make",
51
+ "glsl"=>"Glsl", "markdown"=>"Markdown", "md"=>"Markdown",
52
+ "scheme"=>"Scheme", "apiblueprint"=>"APIBlueprint",
53
+ "applescript"=>"AppleScript", "gradle"=>"Gradle",
54
+ "moonscript"=>"Moonscript", "sed"=>"Sed", "awk"=>"Awk",
55
+ "graphql"=>"GraphQL", "mosel"=>"Mosel", "biml"=>"BIML",
56
+ "groovy"=>"Groovy", "mxml"=>"MXML", "sieve"=>"Sieve",
57
+ "bsl"=>"Bsl", "hack"=>"Hack", "nasm"=>"Nasm", "slim"=>"Slim",
58
+ "haml"=>"Haml", "nginx"=>"Nginx", "smalltalk"=>"Smalltalk",
59
+ "ceylon"=>"Ceylon", "handlebars"=>"Handlebars", "nim"=>"Nim",
60
+ "smarty"=>"Smarty", "cfscript"=>"Cfscript", "haskell"=>"Haskell",
61
+ "nix"=>"Nix", "sml"=>"SML", "clojure"=>"Clojure", "cmake"=>"CMake",
62
+ "http"=>"HTTP", "ocaml"=>"OCaml", "hylang"=>"HyLang",
63
+ "pascal"=>"Pascal", "tap"=>"Tap", "commonlisp"=>"CommonLisp", "idlang"=>"IDLang",
64
+ "tcl"=>"TCL", "conf"=>"Conf", "igorpro"=>"IgorPro",
65
+ "consolelexer"=>"ConsoleLexer", "ini"=>"INI", "plaintext"=>"PlainText",
66
+ "toml"=>"TOML", "coq"=>"Coq", "io"=>"IO", "plist"=>"Plist",
67
+ "tsx"=>"TSX", "irblexer"=>"IRBLexer", "pony"=>"Pony", "tulip"=>"Tulip",
68
+ "irboutputlexer"=>"IRBOutputLexer", "powershell"=>"Powershell", "turtle"=>"Turtle",
69
+ "praat"=>"Praat", "twig"=>"Twig", "d"=>"D","prolog"=>"Prolog",
70
+ "typescript"=>"Typescript", "dart"=>"Dart", "jinja"=>"Jinja",
71
+ "prometheus"=>"Prometheus", "typescriptcommon"=>"TypescriptCommon", "diff"=>"Diff",
72
+ "properties"=>"Properties", "vala"=>"Vala", "digdag"=>"Digdag", "jsondoc"=>"JSONDOC",
73
+ "protobuf"=>"Protobuf", "verilog"=>"Verilog", "docker"=>"Docker", "jsonnet"=>"Jsonnet",
74
+ "puppet"=>"Puppet", "vhdl"=>"VHDL", "dot"=>"Dot", "jsx"=>"JSX",
75
+ "viml"=>"VimL", "eiffel"=>"Eiffel", "julia"=>"Julia", "q"=>"Q",
76
+ "visualbasic"=>"VisualBasic", "elixir"=>"Elixir", "kotlin"=>"Kotlin",
77
+ "qml"=>"Qml", "vue"=>"Vue", "elm"=>"Elm", "lasso"=>"Lasso",
78
+ "wollok"=>"Wollok", "erb"=>"ERB", "liquid"=>"Liquid", "racket"=>"Racket",
79
+ "erlang"=>"Erlang", "literatecoffeescript"=>"LiterateCoffeescript",
80
+ "yaml"=>"YAML", "factor"=>"Factor", "literatehaskell"=>"LiterateHaskell",
81
+ "rust"=>"Rust", "fortran"=>"Fortran", "llvm"=>"LLVM"
82
+ }
83
+ end
84
+ end
@@ -0,0 +1,20 @@
1
+ module Beardown
2
+ class Document
3
+ REGEXP_HEAD = /^(\#{1,6})\s+(.+)(\n)?/
4
+
5
+ def scan_head(s)
6
+ id = s[1].length
7
+ content = s[2]
8
+ render_head id, content
9
+ convert_head id, content
10
+ end
11
+
12
+ def render_head(id, content)
13
+ @title << content if id==1
14
+ end
15
+
16
+ def convert_head(id,content)
17
+ "<h#{id}>#{content}</h#{id}>\n"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ module Beardown
2
+ class Document
3
+ REGEXP_LINE_SEPARATOR = /^---(\n)?/
4
+
5
+ def scan_line_separator(s)
6
+ "<hr>\n"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module Beardown
2
+ class Document
3
+ REGEXP_LIST_ORDERED = /^(\t*) *(\d+)\.\s+(.+)\n?/
4
+ def scan_list_ordered(s)
5
+ t_count = s[1].length
6
+ start_num = s[2].to_i
7
+ content = s[3]
8
+ convert_list_ordered(t_count, start_num, content)
9
+ end
10
+
11
+ def convert_list_ordered(t_count, start_num, content)
12
+ "<ol>" * t_count + %(<ol start="#{start_num}" style="counter-reset:ol #{start_num-1};"><li>) + scan_spans(StringScanner.new(content)) + "</li></ol>" + "</ol>" * t_count + "\n"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,43 @@
1
+ module Beardown
2
+ class Document
3
+ REGEXP_LIST_TODO = /^(\t*) *([\+\-])\s+(.+)\n?/
4
+
5
+ def scan_list_todo(s)
6
+ t_count = s[1].length
7
+ check_status = case s[2]
8
+ when "-" then "uncheck"
9
+ when "+" then "checked"
10
+ end
11
+ content = s[3]
12
+
13
+ ex_svg = :add_extension_todo_svg
14
+ @extensions << ex_svg unless @extensions.include? ex_svg
15
+
16
+ convert_list_todo(t_count, check_status, content)
17
+ end
18
+
19
+ def convert_list_todo(t_count, check_status, content)
20
+ ul_open = %(<ul class='todo-list #{check_status}'><li><svg width="16" height="16" viewBox="0 0 16 16"><use xlink:href="#todobox-#{check_status}"></use></svg>)
21
+ ul_close = %(</li></ul>)
22
+ "<ul>" * t_count + ul_open + scan_spans(StringScanner.new(content)) + ul_close + "</ul>" * t_count + "\n"
23
+ end
24
+
25
+ def add_extension_todo_svg
26
+ <<~HEREDOC
27
+ <svg display="none" version=1.1 xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
28
+ <defs>
29
+ <symbol id="todobox-uncheck"><g fill="none" fill-rule="evenodd">
30
+ <path d="M.5 12.853c0 1.462 1.185 2.647 2.647 2.647h9.706c1.462 0 2.647-1.185 2.647-2.647V3.147C15.5 1.685 14.315.5 12.853.5H3.147C1.685.5.5 1.685.5 3.147v9.706z" fill="#FFF"/>
31
+ <path d="M.5 12.853c0 1.462 1.185 2.647 2.647 2.647h9.706c1.462 0 2.647-1.185 2.647-2.647V3.147C15.5 1.685 14.315.5 12.853.5H3.147C1.685.5.5 1.685.5 3.147v9.706z" stroke="#B4B4B4"/></g>
32
+ </symbol>
33
+ <symbol id="todobox-checked"><g fill="none" fill-rule="evenodd">
34
+ <path d="M.5 12.853c0 1.462 1.185 2.647 2.647 2.647h9.706c1.462 0 2.647-1.185 2.647-2.647V3.147C15.5 1.685 14.315.5 12.853.5H3.147C1.685.5.5 1.685.5 3.147v9.706z" fill="#FFF"/>
35
+ <path d="M.5 12.853c0 1.462 1.185 2.647 2.647 2.647h9.706c1.462 0 2.647-1.185 2.647-2.647V3.147C15.5 1.685 14.315.5 12.853.5H3.147C1.685.5.5 1.685.5 3.147v9.706z" stroke="#B4B4B4"/>
36
+ <path d="M12.526 4.615L6.636 9.58l-2.482-.836c-.19-.06-.408.003-.518.15-.116.15-.106.352.026.495l2.722 2.91c.086.09.21.144.34.144h.046c.12-.013.234-.07.307-.156l6.1-7.125c.143-.166.123-.407-.046-.548-.164-.138-.435-.14-.604 0z" fill="#555"/></g></symbol>
37
+ </defs>
38
+ </svg>
39
+ HEREDOC
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1,14 @@
1
+ module Beardown
2
+ class Document
3
+ REGEXP_LIST_UNORDERED = /^(\t*) *\*\s+(.+)(\n)?/
4
+ def scan_list_unordered(s)
5
+ t_count = s[1].length
6
+ content = s[2]
7
+ convert_list_unordered(t_count, content)
8
+ end
9
+
10
+ def convert_list_unordered(t_count, content)
11
+ "<ul>" * t_count + "<ul><li>" + scan_spans(StringScanner.new(content)) + "</li></ul>" + "</ul>" * t_count + "\n"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module Beardown
2
+ class Document
3
+ REGEXP_P = /^(\s*)(.+)\n?/
4
+
5
+ def scan_p(s)
6
+ indent = s[1].length
7
+ content = s[2]
8
+ convert_p indent, content
9
+ end
10
+
11
+ def convert_p(indent, content)
12
+ "<p>#{"&emsp;"*indent}#{scan_spans(StringScanner.new(content))}</p>\n"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module Beardown
2
+ class Document
3
+ REGEXP_QUOTE = /^>\s+(.+)\n?/
4
+
5
+ def scan_quote(s)
6
+ content = s[1]
7
+ convert_quote(content)
8
+ end
9
+
10
+ def convert_quote(content)
11
+ "<blockquote>#{scan_spans(StringScanner.new(content))}</blockquote>\n"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,124 @@
1
+ require 'strscan'
2
+
3
+ module Beardown
4
+ class Document
5
+
6
+ def initialize(text)
7
+ @text = text
8
+
9
+ # These orders are important
10
+ @blocks = [:head, :line_separator, :list_unordered, :list_ordered,
11
+ :quote, :list_todo, :codeblock, :asset, :blankline, :p]
12
+ @spans = [:codespan, :hashtag_full, :hashtag_full_nospace, :hashtag, :linkpost, :linkurl,
13
+ :bold, :italic, :underline, :strike, :mark_nospace, :mark]
14
+
15
+ @extensions = Array.new
16
+ @title = String.new
17
+ @tags = Array.new
18
+
19
+ html
20
+ end
21
+
22
+ def title
23
+ @title
24
+ end
25
+
26
+ def tags
27
+ @tags
28
+ end
29
+
30
+ # def assets
31
+ # return @assets unless defined?(@assets).nil?
32
+ #end
33
+
34
+ def content
35
+ return @content if defined? @content
36
+ @content = @text.delete "\n", "\t", "\s", "#", "*", "`", "*", "-", "_", "=", "+", "[", "]", ":", "<", ">"
37
+ end
38
+
39
+ def summary
40
+ return @summary if defined? @summary
41
+ s = content
42
+ @summary = s[0...30]
43
+ end
44
+
45
+ def html
46
+ return @html if defined? @html
47
+ to_html
48
+ end
49
+
50
+ def to_html
51
+ return @html if defined? @html
52
+ s = StringScanner.new @text
53
+ res = String.new
54
+ while !s.eos? do
55
+ res << scan_blocks(s)
56
+ end
57
+ res << add_extensions
58
+ @html = res
59
+ end
60
+
61
+ protected
62
+
63
+ def scan_blocks(s)
64
+ @blocks.each do |e|
65
+ #begin
66
+ unless s.scan(Document.const_get("REGEXP_#{e.to_s.upcase}")).nil?
67
+ return send "scan_#{e.to_s}", s
68
+ end
69
+ #rescue NameError
70
+ # next
71
+ #end
72
+ end
73
+ return s.string
74
+ end
75
+
76
+ def regexp_span_like
77
+ return @regexp_span_like if defined? @regexp_span_like
78
+ res = String.new
79
+ @spans.each do |e|
80
+ begin
81
+ start_char = Document.const_get("START_CHAR_#{e.to_s.upcase}")
82
+ res << "\\#{start_char}"
83
+ rescue NameError
84
+ next
85
+ end
86
+ end
87
+ @regexp_span_like = /[#{res}]/
88
+ end
89
+
90
+ def scan_spans(s)
91
+ while !s.eos?
92
+ last_pos = s.pos
93
+ like = s.scan_until regexp_span_like
94
+ if like
95
+ s.pos -= 1
96
+ pre = s.pre_match.to_s
97
+ @spans.each do |e|
98
+ #begin
99
+ match = s.scan Document.const_get("REGEXP_#{e.to_s.upcase}")
100
+ #rescue NameError
101
+ # next
102
+ #end
103
+ if match
104
+ return pre + send("scan_#{e.to_s}", s) + scan_spans(StringScanner.new(s.rest))
105
+ end
106
+ end
107
+ s.pos = last_pos + 1
108
+ else
109
+ break
110
+ end
111
+ end
112
+ return s.string
113
+ end
114
+
115
+ def add_extensions
116
+ res = String.new
117
+ @extensions.each do |ex|
118
+ res << send(ex)
119
+ end
120
+ res
121
+ end
122
+
123
+ end
124
+ end
@@ -0,0 +1,25 @@
1
+ module Beardown
2
+ class Document
3
+ START_CHAR_BOLD = "*"
4
+ START_CHAR_ITALIC = "/"
5
+ START_CHAR_UNDERLINE = "_"
6
+ START_CHAR_STRIKE = "-"
7
+
8
+ REGEXP_BOLD = /\*(.*?[^\s])\*/
9
+ REGEXP_ITALIC = /\/(.*?[^\s])\//
10
+ REGEXP_UNDERLINE = /\_(.*?[^\s])\_/
11
+ REGEXP_STRIKE = /\-(.*?[^\s])\-/
12
+
13
+ ["bold", "italic", "underline", "strike"].each do |attr|
14
+ define_method :"scan_#{attr}" do |s|
15
+ content = s[1]
16
+ send "convert_#{attr}", content
17
+ end
18
+
19
+ define_method :"convert_#{attr}" do |content|
20
+ tag = attr[0]
21
+ %(<#{tag}>#{scan_spans(StringScanner.new(content))}</#{tag}>)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ module Beardown
2
+ class Document
3
+ START_CHAR_CODESPAN = "`"
4
+ REGEXP_CODESPAN = /`(.*?)`/
5
+
6
+ def scan_codespan(s)
7
+ code = s[1]
8
+ convert_codespan code
9
+ end
10
+
11
+ def convert_codespan(code)
12
+ %(<code class="code-inline">#{code}</code>)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,37 @@
1
+ module Beardown
2
+ class Document
3
+ START_CHAR_HASHTAG = "#"
4
+
5
+ REGEXP_HASHTAG_FULL = /#([^\s^#][^#]*[^\s^#])#/
6
+ REGEXP_HASHTAG_FULL_NOSPACE = /#([^#^\s]+)#/
7
+ REGEXP_HASHTAG = /#([^#\s\,]+)/
8
+
9
+ ["", "_full", "_full_nospace"].each do |attr|
10
+ define_method :"scan_hashtag#{attr}" do |s|
11
+ tag = s[1]
12
+ send "convert_hashtag#{attr}", tag
13
+ end
14
+
15
+ define_method :"convert_hashtag#{attr}" do |tag|
16
+ tag = tag.downcase
17
+ render_hashtag tag
18
+ sym = case attr
19
+ when "" then ""
20
+ else "#"
21
+ end
22
+ %(<a href="../tag/#{tag}/" class="hashtag">##{tag+sym}</a>)
23
+ end
24
+ end
25
+
26
+ def render_hashtag(tag)
27
+ tag = tag.downcase
28
+ tags = tag.split "/"
29
+ _tag = tags[0]
30
+ @tags << _tag unless @tags.include? _tag
31
+ tags[1..-1].each do |t|
32
+ _tag += "/#{t}"
33
+ @tags << _tag unless @tags.include? _tag
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,18 @@
1
+ module Beardown
2
+ class Document
3
+ START_CHAR_LINKPOST = "["
4
+ REGEXP_LINKPOST = /\[\[(.+)\]\]/
5
+
6
+ # I use this not as a X callback url Scheme
7
+ # Instead, A url to this website used in Miyano Blog system
8
+
9
+ def scan_linkpost(s)
10
+ title = s[1]
11
+ convert_linkpost(title)
12
+ end
13
+
14
+ def convert_linkpost(title)
15
+ %(<a href="../#{title}/">#{title}</a>)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module Beardown
2
+ class Document
3
+ # START_CHAR_LINKURL = "[" # duplicate with LINKPOST
4
+ REGEXP_LINKURL = /\[(.+)\]\((.+)\)/
5
+
6
+ def scan_linkurl(s)
7
+ title, url = s[1], s[2]
8
+ convert_linkurl(title, url)
9
+ end
10
+
11
+ def convert_linkurl(title,url)
12
+ %(<a href="#{url}">#{title}</a>)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ module Beardown
2
+ class Document
3
+ START_CHAR_MARK = ":"
4
+ REGEXP_MARK = /::([^\s].*[^\s])::/
5
+ REGEXP_MARK_NOSPACE = /::([^\s]*)::/
6
+
7
+ ["", "_nospace"].each do |attr|
8
+ define_method :"scan_mark#{attr}" do |s|
9
+ content = s[1]
10
+ send "convert_mark#{attr}", content
11
+ end
12
+
13
+ define_method :"convert_mark#{attr}" do |content|
14
+ %(<mark>#{scan_spans(StringScanner.new(content))}</mark>)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Beardown
2
+ VERSION = "0.1.4"
3
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beardown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - wuusn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rouge
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.1.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.1.1
69
+ description:
70
+ email:
71
+ - wuusin@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - beardown.gemspec
85
+ - lib/beardown.rb
86
+ - lib/beardown/blocks/asset.rb
87
+ - lib/beardown/blocks/blankline.rb
88
+ - lib/beardown/blocks/codeblock.rb
89
+ - lib/beardown/blocks/head.rb
90
+ - lib/beardown/blocks/line_separator.rb
91
+ - lib/beardown/blocks/list_ordered.rb
92
+ - lib/beardown/blocks/list_todo.rb
93
+ - lib/beardown/blocks/list_unordered.rb
94
+ - lib/beardown/blocks/p.rb
95
+ - lib/beardown/blocks/quote.rb
96
+ - lib/beardown/document.rb
97
+ - lib/beardown/spans/bold_italic_underline_strike.rb
98
+ - lib/beardown/spans/codespan.rb
99
+ - lib/beardown/spans/hashtag.rb
100
+ - lib/beardown/spans/linkpost.rb
101
+ - lib/beardown/spans/linkurl.rb
102
+ - lib/beardown/spans/mark.rb
103
+ - lib/beardown/version.rb
104
+ homepage: https://github.com/wuusn/beardown
105
+ licenses:
106
+ - MIT
107
+ metadata:
108
+ allowed_push_host: https://rubygems.org
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.7.6
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: A html convertor for Bear App's bearnote - Polar Bear markup language.
129
+ test_files: []