Class: Markascend::Env
- Inherits:
-
Object
- Object
- Markascend::Env
- Defined in:
- lib/markascend/env.rb
Instance Attribute Summary collapse
-
#autolink ⇒ Object
readonly
Returns the value of attribute autolink.
-
#footnotes ⇒ Object
readonly
Returns the value of attribute footnotes.
-
#hi ⇒ Object
Returns the value of attribute hi.
-
#inline_img ⇒ Object
readonly
Returns the value of attribute inline_img.
-
#line_units ⇒ Object
readonly
Returns the value of attribute line_units.
-
#macros ⇒ Object
readonly
Returns the value of attribute macros.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pwd ⇒ Object
readonly
Returns the value of attribute pwd.
-
#sandbox ⇒ Object
readonly
Returns the value of attribute sandbox.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#srcs ⇒ Object
readonly
Returns the value of attribute srcs.
-
#toc ⇒ Object
readonly
Returns the value of attribute toc.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#initialize(autolink: %w[http https ftp mailto],, inline_img: false, sandbox: false, toc: false, **opts) ⇒ Env
constructor
A new instance of Env.
- #warn(msg) ⇒ Object
Constructor Details
#initialize(autolink: %w[http https ftp mailto],, inline_img: false, sandbox: false, toc: false, **opts) ⇒ Env
Returns a new instance of Env.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/markascend/env.rb', line 7 def initialize(autolink: %w[http https ftp mailto], inline_img: false, sandbox: false, toc: false, **opts) @autolink = autolink @inline_img = inline_img @sandbox = sandbox @toc = toc ? {} : false # {id => [x, header_content]} if opts[:path] pwd = File.dirname opts[:path] if File.directory?(pwd) @pwd = pwd end end if opts[:macros] @macros = {} opts[:macros].each do |m| meth = "parse_#{m}" if Macro.respond_to?(meth) @macros[m] = meth else raise ArgumentError, "macro processor #{meth} not defined" end end elsif @sandbox @macros = SANDBOX_MACROS else @macros = DEFAULT_MACROS end if opts[:line_units] @line_units = opts[:line_units].map do |m| meth = "parse_#{m}" if LineUnit.respond_to?(meth) meth else raise ArgumentError, "line-unit parser #{meth} not defined" end end else @line_units = DEFAULT_LINE_UNITS end @scope = opts[:scope] || Object.new.send(:binding) @options = {} # for \options macro @footnotes = {} # {abbrev => details}. for [.] and [:] elements @srcs = [] # recursive parser stack, everyone has the contiguous right one scanned @warnings = {} # {line => message} @hi = nil # current syntax hiliter end |
Instance Attribute Details
#autolink ⇒ Object (readonly)
Returns the value of attribute autolink.
3 4 5 |
# File 'lib/markascend/env.rb', line 3 def autolink @autolink end |
#footnotes ⇒ Object (readonly)
Returns the value of attribute footnotes.
4 5 6 |
# File 'lib/markascend/env.rb', line 4 def footnotes @footnotes end |
#hi ⇒ Object
Returns the value of attribute hi.
5 6 7 |
# File 'lib/markascend/env.rb', line 5 def hi @hi end |
#inline_img ⇒ Object (readonly)
Returns the value of attribute inline_img.
3 4 5 |
# File 'lib/markascend/env.rb', line 3 def inline_img @inline_img end |
#line_units ⇒ Object (readonly)
Returns the value of attribute line_units.
4 5 6 |
# File 'lib/markascend/env.rb', line 4 def line_units @line_units end |
#macros ⇒ Object (readonly)
Returns the value of attribute macros.
4 5 6 |
# File 'lib/markascend/env.rb', line 4 def macros @macros end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/markascend/env.rb', line 4 def @options end |
#pwd ⇒ Object (readonly)
Returns the value of attribute pwd.
3 4 5 |
# File 'lib/markascend/env.rb', line 3 def pwd @pwd end |
#sandbox ⇒ Object (readonly)
Returns the value of attribute sandbox.
3 4 5 |
# File 'lib/markascend/env.rb', line 3 def sandbox @sandbox end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
4 5 6 |
# File 'lib/markascend/env.rb', line 4 def scope @scope end |
#srcs ⇒ Object (readonly)
Returns the value of attribute srcs.
4 5 6 |
# File 'lib/markascend/env.rb', line 4 def srcs @srcs end |
#toc ⇒ Object (readonly)
Returns the value of attribute toc.
3 4 5 |
# File 'lib/markascend/env.rb', line 3 def toc @toc end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
4 5 6 |
# File 'lib/markascend/env.rb', line 4 def warnings @warnings end |
Instance Method Details
#warn(msg) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/markascend/env.rb', line 57 def warn msg if @srcs.size current_src = @srcs.last line = @srcs.first.string.count("\n") - current_src.string[(current_src.pos)..-1].count("\n") @warnings[line] = msg else # warnings without source is set to line 0 @warnings[0] = msg end end |