Module: Kozeki::MarkdownLoader
- Defined in:
- lib/kozeki/markdown_loader.rb
Class Method Summary collapse
Class Method Details
.build(source) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kozeki/markdown_loader.rb', line 27 def self.build(source) html = Commonmarker.to_html(source.content, options: { render: { unsafe: true, }, extension: { strikethrough: true, tagfilter: false, table: true, autolink: true, tasklist: true, superscript: true, header_ids: "#{source.id}--", footnotes: true, description_lists: true, front_matter_delimiter: '---', shortcodes: true, }, }) { html: html, } end |
.try_read(path:, filesystem:) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/kozeki/markdown_loader.rb', line 8 def self.try_read(path:, filesystem:) basename = path.last return nil unless basename.end_with?('.md') || basename.end_with?('.mkd') || basename.end_with?('.markdown') content, mtime = filesystem.read_with_mtime(path) m = content.match(/\A\s*^---$(.+?)^---$/m) = if m YAML.safe_load(m[1], symbolize_names: true) else {} end Source.new( path:, meta:, mtime:, content:, loader: self, ) end |