commonmarker 0.23.10 → 2.1.1
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 +4 -4
 - data/Cargo.lock +1156 -0
 - data/Cargo.toml +7 -0
 - data/README.md +237 -172
 - data/ext/commonmarker/Cargo.toml +20 -0
 - data/ext/commonmarker/extconf.rb +3 -6
 - data/ext/commonmarker/src/lib.rs +103 -0
 - data/ext/commonmarker/src/node.rs +1221 -0
 - data/ext/commonmarker/src/options.rs +220 -0
 - data/ext/commonmarker/src/plugins/syntax_highlighting.rs +166 -0
 - data/ext/commonmarker/src/plugins.rs +6 -0
 - data/ext/commonmarker/src/utils.rs +8 -0
 - data/lib/commonmarker/config.rb +92 -40
 - data/lib/commonmarker/constants.rb +7 -0
 - data/lib/commonmarker/extension.rb +14 -0
 - data/lib/commonmarker/node/ast.rb +8 -0
 - data/lib/commonmarker/node/inspect.rb +14 -4
 - data/lib/commonmarker/node.rb +29 -47
 - data/lib/commonmarker/renderer.rb +1 -127
 - data/lib/commonmarker/utils.rb +22 -0
 - data/lib/commonmarker/version.rb +2 -2
 - data/lib/commonmarker.rb +27 -25
 - metadata +38 -191
 - data/Rakefile +0 -109
 - data/bin/commonmarker +0 -118
 - data/commonmarker.gemspec +0 -38
 - data/ext/commonmarker/arena.c +0 -104
 - data/ext/commonmarker/autolink.c +0 -508
 - data/ext/commonmarker/autolink.h +0 -8
 - data/ext/commonmarker/blocks.c +0 -1622
 - data/ext/commonmarker/buffer.c +0 -278
 - data/ext/commonmarker/buffer.h +0 -116
 - data/ext/commonmarker/case_fold_switch.inc +0 -4327
 - data/ext/commonmarker/chunk.h +0 -135
 - data/ext/commonmarker/cmark-gfm-core-extensions.h +0 -54
 - data/ext/commonmarker/cmark-gfm-extension_api.h +0 -737
 - data/ext/commonmarker/cmark-gfm-extensions_export.h +0 -42
 - data/ext/commonmarker/cmark-gfm.h +0 -833
 - data/ext/commonmarker/cmark-gfm_export.h +0 -42
 - data/ext/commonmarker/cmark-gfm_version.h +0 -7
 - data/ext/commonmarker/cmark.c +0 -55
 - data/ext/commonmarker/cmark_ctype.c +0 -44
 - data/ext/commonmarker/cmark_ctype.h +0 -33
 - data/ext/commonmarker/commonmark.c +0 -514
 - data/ext/commonmarker/commonmarker.c +0 -1308
 - data/ext/commonmarker/commonmarker.h +0 -16
 - data/ext/commonmarker/config.h +0 -76
 - data/ext/commonmarker/core-extensions.c +0 -27
 - data/ext/commonmarker/entities.inc +0 -2138
 - data/ext/commonmarker/ext_scanners.c +0 -879
 - data/ext/commonmarker/ext_scanners.h +0 -24
 - data/ext/commonmarker/footnotes.c +0 -63
 - data/ext/commonmarker/footnotes.h +0 -27
 - data/ext/commonmarker/houdini.h +0 -57
 - data/ext/commonmarker/houdini_href_e.c +0 -100
 - data/ext/commonmarker/houdini_html_e.c +0 -66
 - data/ext/commonmarker/houdini_html_u.c +0 -149
 - data/ext/commonmarker/html.c +0 -502
 - data/ext/commonmarker/html.h +0 -27
 - data/ext/commonmarker/inlines.c +0 -1788
 - data/ext/commonmarker/inlines.h +0 -29
 - data/ext/commonmarker/iterator.c +0 -159
 - data/ext/commonmarker/iterator.h +0 -26
 - data/ext/commonmarker/latex.c +0 -468
 - data/ext/commonmarker/linked_list.c +0 -37
 - data/ext/commonmarker/man.c +0 -274
 - data/ext/commonmarker/map.c +0 -129
 - data/ext/commonmarker/map.h +0 -44
 - data/ext/commonmarker/node.c +0 -1045
 - data/ext/commonmarker/node.h +0 -167
 - data/ext/commonmarker/parser.h +0 -59
 - data/ext/commonmarker/plaintext.c +0 -218
 - data/ext/commonmarker/plugin.c +0 -36
 - data/ext/commonmarker/plugin.h +0 -34
 - data/ext/commonmarker/references.c +0 -43
 - data/ext/commonmarker/references.h +0 -26
 - data/ext/commonmarker/registry.c +0 -63
 - data/ext/commonmarker/registry.h +0 -24
 - data/ext/commonmarker/render.c +0 -213
 - data/ext/commonmarker/render.h +0 -62
 - data/ext/commonmarker/scanners.c +0 -14056
 - data/ext/commonmarker/scanners.h +0 -70
 - data/ext/commonmarker/scanners.re +0 -341
 - data/ext/commonmarker/strikethrough.c +0 -167
 - data/ext/commonmarker/strikethrough.h +0 -9
 - data/ext/commonmarker/syntax_extension.c +0 -149
 - data/ext/commonmarker/syntax_extension.h +0 -34
 - data/ext/commonmarker/table.c +0 -917
 - data/ext/commonmarker/table.h +0 -12
 - data/ext/commonmarker/tagfilter.c +0 -60
 - data/ext/commonmarker/tagfilter.h +0 -8
 - data/ext/commonmarker/tasklist.c +0 -156
 - data/ext/commonmarker/tasklist.h +0 -8
 - data/ext/commonmarker/utf8.c +0 -317
 - data/ext/commonmarker/utf8.h +0 -35
 - data/ext/commonmarker/xml.c +0 -182
 - data/lib/commonmarker/renderer/html_renderer.rb +0 -256
 
| 
         @@ -0,0 +1,220 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            use std::borrow::Cow;
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            use comrak::ComrakOptions;
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            use magnus::value::ReprValue;
         
     | 
| 
      
 6 
     | 
    
         
            +
            use magnus::TryConvert;
         
     | 
| 
      
 7 
     | 
    
         
            +
            use magnus::{class, r_hash::ForEach, Error, RHash, Symbol, Value};
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            use crate::utils::try_convert_string;
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            const PARSE_SMART: &str = "smart";
         
     | 
| 
      
 12 
     | 
    
         
            +
            const PARSE_DEFAULT_INFO_STRING: &str = "default_info_string";
         
     | 
| 
      
 13 
     | 
    
         
            +
            const PARSE_RELAXED_TASKLIST_MATCHING: &str = "relaxed_tasklist_matching";
         
     | 
| 
      
 14 
     | 
    
         
            +
            const PARSE_RELAXED_AUTOLINKS: &str = "relaxed_autolinks";
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            fn iterate_parse_options(comrak_options: &mut ComrakOptions, options_hash: RHash) {
         
     | 
| 
      
 17 
     | 
    
         
            +
                options_hash
         
     | 
| 
      
 18 
     | 
    
         
            +
                    .foreach(|key: Symbol, value: Value| {
         
     | 
| 
      
 19 
     | 
    
         
            +
                        match key.name() {
         
     | 
| 
      
 20 
     | 
    
         
            +
                            Ok(Cow::Borrowed(PARSE_SMART)) => {
         
     | 
| 
      
 21 
     | 
    
         
            +
                                comrak_options.parse.smart = TryConvert::try_convert(value)?;
         
     | 
| 
      
 22 
     | 
    
         
            +
                            }
         
     | 
| 
      
 23 
     | 
    
         
            +
                            Ok(Cow::Borrowed(PARSE_DEFAULT_INFO_STRING)) => {
         
     | 
| 
      
 24 
     | 
    
         
            +
                                comrak_options.parse.default_info_string = try_convert_string(value);
         
     | 
| 
      
 25 
     | 
    
         
            +
                            }
         
     | 
| 
      
 26 
     | 
    
         
            +
                            Ok(Cow::Borrowed(PARSE_RELAXED_TASKLIST_MATCHING)) => {
         
     | 
| 
      
 27 
     | 
    
         
            +
                                comrak_options.parse.relaxed_tasklist_matching =
         
     | 
| 
      
 28 
     | 
    
         
            +
                                    TryConvert::try_convert(value)?;
         
     | 
| 
      
 29 
     | 
    
         
            +
                            }
         
     | 
| 
      
 30 
     | 
    
         
            +
                            Ok(Cow::Borrowed(PARSE_RELAXED_AUTOLINKS)) => {
         
     | 
| 
      
 31 
     | 
    
         
            +
                                comrak_options.parse.relaxed_autolinks = TryConvert::try_convert(value)?;
         
     | 
| 
      
 32 
     | 
    
         
            +
                            }
         
     | 
| 
      
 33 
     | 
    
         
            +
                            _ => {}
         
     | 
| 
      
 34 
     | 
    
         
            +
                        }
         
     | 
| 
      
 35 
     | 
    
         
            +
                        Ok(ForEach::Continue)
         
     | 
| 
      
 36 
     | 
    
         
            +
                    })
         
     | 
| 
      
 37 
     | 
    
         
            +
                    .unwrap();
         
     | 
| 
      
 38 
     | 
    
         
            +
            }
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            const RENDER_HARDBREAKS: &str = "hardbreaks";
         
     | 
| 
      
 41 
     | 
    
         
            +
            const RENDER_GITHUB_PRE_LANG: &str = "github_pre_lang";
         
     | 
| 
      
 42 
     | 
    
         
            +
            const RENDER_FULL_INFO_STRING: &str = "full_info_string";
         
     | 
| 
      
 43 
     | 
    
         
            +
            const RENDER_WIDTH: &str = "width";
         
     | 
| 
      
 44 
     | 
    
         
            +
            const RENDER_UNSAFE: &str = "unsafe";
         
     | 
| 
      
 45 
     | 
    
         
            +
            const RENDER_ESCAPE: &str = "escape";
         
     | 
| 
      
 46 
     | 
    
         
            +
            const RENDER_SOURCEPOS: &str = "sourcepos";
         
     | 
| 
      
 47 
     | 
    
         
            +
            const RENDER_ESCAPED_CHAR_SPANS: &str = "escaped_char_spans";
         
     | 
| 
      
 48 
     | 
    
         
            +
            const RENDER_IGNORE_SETEXT: &str = "ignore_setext";
         
     | 
| 
      
 49 
     | 
    
         
            +
            const RENDER_IGNORE_EMPTY_LINKS: &str = "ignore_empty_links";
         
     | 
| 
      
 50 
     | 
    
         
            +
            const RENDER_GFM_QUIRKS: &str = "gfm_quirks";
         
     | 
| 
      
 51 
     | 
    
         
            +
            const RENDER_PREFER_FENCED: &str = "prefer_fenced";
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
            fn iterate_render_options(comrak_options: &mut ComrakOptions, options_hash: RHash) {
         
     | 
| 
      
 54 
     | 
    
         
            +
                options_hash
         
     | 
| 
      
 55 
     | 
    
         
            +
                    .foreach(|key: Symbol, value: Value| {
         
     | 
| 
      
 56 
     | 
    
         
            +
                        match key.name() {
         
     | 
| 
      
 57 
     | 
    
         
            +
                            Ok(Cow::Borrowed(RENDER_HARDBREAKS)) => {
         
     | 
| 
      
 58 
     | 
    
         
            +
                                comrak_options.render.hardbreaks = TryConvert::try_convert(value)?;
         
     | 
| 
      
 59 
     | 
    
         
            +
                            }
         
     | 
| 
      
 60 
     | 
    
         
            +
                            Ok(Cow::Borrowed(RENDER_GITHUB_PRE_LANG)) => {
         
     | 
| 
      
 61 
     | 
    
         
            +
                                comrak_options.render.github_pre_lang = TryConvert::try_convert(value)?;
         
     | 
| 
      
 62 
     | 
    
         
            +
                            }
         
     | 
| 
      
 63 
     | 
    
         
            +
                            Ok(Cow::Borrowed(RENDER_FULL_INFO_STRING)) => {
         
     | 
| 
      
 64 
     | 
    
         
            +
                                comrak_options.render.full_info_string = TryConvert::try_convert(value)?;
         
     | 
| 
      
 65 
     | 
    
         
            +
                            }
         
     | 
| 
      
 66 
     | 
    
         
            +
                            Ok(Cow::Borrowed(RENDER_WIDTH)) => {
         
     | 
| 
      
 67 
     | 
    
         
            +
                                comrak_options.render.width = TryConvert::try_convert(value)?;
         
     | 
| 
      
 68 
     | 
    
         
            +
                            }
         
     | 
| 
      
 69 
     | 
    
         
            +
                            Ok(Cow::Borrowed(RENDER_UNSAFE)) => {
         
     | 
| 
      
 70 
     | 
    
         
            +
                                comrak_options.render.unsafe_ = TryConvert::try_convert(value)?;
         
     | 
| 
      
 71 
     | 
    
         
            +
                            }
         
     | 
| 
      
 72 
     | 
    
         
            +
                            Ok(Cow::Borrowed(RENDER_ESCAPE)) => {
         
     | 
| 
      
 73 
     | 
    
         
            +
                                comrak_options.render.escape = TryConvert::try_convert(value)?;
         
     | 
| 
      
 74 
     | 
    
         
            +
                            }
         
     | 
| 
      
 75 
     | 
    
         
            +
                            Ok(Cow::Borrowed(RENDER_SOURCEPOS)) => {
         
     | 
| 
      
 76 
     | 
    
         
            +
                                comrak_options.render.sourcepos = TryConvert::try_convert(value)?;
         
     | 
| 
      
 77 
     | 
    
         
            +
                            }
         
     | 
| 
      
 78 
     | 
    
         
            +
                            Ok(Cow::Borrowed(RENDER_ESCAPED_CHAR_SPANS)) => {
         
     | 
| 
      
 79 
     | 
    
         
            +
                                comrak_options.render.escaped_char_spans = TryConvert::try_convert(value)?;
         
     | 
| 
      
 80 
     | 
    
         
            +
                            }
         
     | 
| 
      
 81 
     | 
    
         
            +
                            Ok(Cow::Borrowed(RENDER_IGNORE_SETEXT)) => {
         
     | 
| 
      
 82 
     | 
    
         
            +
                                comrak_options.render.ignore_setext = TryConvert::try_convert(value)?;
         
     | 
| 
      
 83 
     | 
    
         
            +
                            }
         
     | 
| 
      
 84 
     | 
    
         
            +
                            Ok(Cow::Borrowed(RENDER_IGNORE_EMPTY_LINKS)) => {
         
     | 
| 
      
 85 
     | 
    
         
            +
                                comrak_options.render.ignore_empty_links = TryConvert::try_convert(value)?;
         
     | 
| 
      
 86 
     | 
    
         
            +
                            }
         
     | 
| 
      
 87 
     | 
    
         
            +
                            Ok(Cow::Borrowed(RENDER_GFM_QUIRKS)) => {
         
     | 
| 
      
 88 
     | 
    
         
            +
                                comrak_options.render.gfm_quirks = TryConvert::try_convert(value)?;
         
     | 
| 
      
 89 
     | 
    
         
            +
                            }
         
     | 
| 
      
 90 
     | 
    
         
            +
                            Ok(Cow::Borrowed(RENDER_PREFER_FENCED)) => {
         
     | 
| 
      
 91 
     | 
    
         
            +
                                comrak_options.render.prefer_fenced = TryConvert::try_convert(value)?;
         
     | 
| 
      
 92 
     | 
    
         
            +
                            }
         
     | 
| 
      
 93 
     | 
    
         
            +
                            _ => {}
         
     | 
| 
      
 94 
     | 
    
         
            +
                        }
         
     | 
| 
      
 95 
     | 
    
         
            +
                        Ok(ForEach::Continue)
         
     | 
| 
      
 96 
     | 
    
         
            +
                    })
         
     | 
| 
      
 97 
     | 
    
         
            +
                    .unwrap();
         
     | 
| 
      
 98 
     | 
    
         
            +
            }
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
            const EXTENSION_STRIKETHROUGH: &str = "strikethrough";
         
     | 
| 
      
 101 
     | 
    
         
            +
            const EXTENSION_TAGFILTER: &str = "tagfilter";
         
     | 
| 
      
 102 
     | 
    
         
            +
            const EXTENSION_TABLE: &str = "table";
         
     | 
| 
      
 103 
     | 
    
         
            +
            const EXTENSION_AUTOLINK: &str = "autolink";
         
     | 
| 
      
 104 
     | 
    
         
            +
            const EXTENSION_TASKLIST: &str = "tasklist";
         
     | 
| 
      
 105 
     | 
    
         
            +
            const EXTENSION_SUPERSCRIPT: &str = "superscript";
         
     | 
| 
      
 106 
     | 
    
         
            +
            const EXTENSION_HEADER_IDS: &str = "header_ids";
         
     | 
| 
      
 107 
     | 
    
         
            +
            const EXTENSION_FOOTNOTES: &str = "footnotes";
         
     | 
| 
      
 108 
     | 
    
         
            +
            const EXTENSION_DESCRIPTION_LISTS: &str = "description_lists";
         
     | 
| 
      
 109 
     | 
    
         
            +
            const EXTENSION_FRONT_MATTER_DELIMITER: &str = "front_matter_delimiter";
         
     | 
| 
      
 110 
     | 
    
         
            +
            const EXTENSION_MULTILINE_BLOCK_QUOTES: &str = "multiline_block_quotes";
         
     | 
| 
      
 111 
     | 
    
         
            +
            const EXTENSION_MATH_DOLLARS: &str = "math_dollars";
         
     | 
| 
      
 112 
     | 
    
         
            +
            const EXTENSION_MATH_CODE: &str = "math_code";
         
     | 
| 
      
 113 
     | 
    
         
            +
            const EXTENSION_SHORTCODES: &str = "shortcodes";
         
     | 
| 
      
 114 
     | 
    
         
            +
            const EXTENSION_WIKILINKS_TITLE_AFTER_PIPE: &str = "wikilinks_title_after_pipe";
         
     | 
| 
      
 115 
     | 
    
         
            +
            const EXTENSION_WIKILINKS_TITLE_BEFORE_PIPE: &str = "wikilinks_title_before_pipe";
         
     | 
| 
      
 116 
     | 
    
         
            +
            const EXTENSION_UNDERLINE: &str = "underline";
         
     | 
| 
      
 117 
     | 
    
         
            +
            const EXTENSION_SPOILER: &str = "spoiler";
         
     | 
| 
      
 118 
     | 
    
         
            +
            const EXTENSION_GREENTEXT: &str = "greentext";
         
     | 
| 
      
 119 
     | 
    
         
            +
            const EXTENSION_SUBSCRIPT: &str = "subscript";
         
     | 
| 
      
 120 
     | 
    
         
            +
            const EXTENSION_ALERTS: &str = "alerts";
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
            fn iterate_extension_options(comrak_options: &mut ComrakOptions, options_hash: RHash) {
         
     | 
| 
      
 123 
     | 
    
         
            +
                options_hash
         
     | 
| 
      
 124 
     | 
    
         
            +
                    .foreach(|key: Symbol, value: Value| {
         
     | 
| 
      
 125 
     | 
    
         
            +
                        match key.name() {
         
     | 
| 
      
 126 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_STRIKETHROUGH)) => {
         
     | 
| 
      
 127 
     | 
    
         
            +
                                comrak_options.extension.strikethrough = TryConvert::try_convert(value)?;
         
     | 
| 
      
 128 
     | 
    
         
            +
                            }
         
     | 
| 
      
 129 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_TAGFILTER)) => {
         
     | 
| 
      
 130 
     | 
    
         
            +
                                comrak_options.extension.tagfilter = TryConvert::try_convert(value)?;
         
     | 
| 
      
 131 
     | 
    
         
            +
                            }
         
     | 
| 
      
 132 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_TABLE)) => {
         
     | 
| 
      
 133 
     | 
    
         
            +
                                comrak_options.extension.table = TryConvert::try_convert(value)?;
         
     | 
| 
      
 134 
     | 
    
         
            +
                            }
         
     | 
| 
      
 135 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_AUTOLINK)) => {
         
     | 
| 
      
 136 
     | 
    
         
            +
                                comrak_options.extension.autolink = TryConvert::try_convert(value)?;
         
     | 
| 
      
 137 
     | 
    
         
            +
                            }
         
     | 
| 
      
 138 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_TASKLIST)) => {
         
     | 
| 
      
 139 
     | 
    
         
            +
                                comrak_options.extension.tasklist = TryConvert::try_convert(value)?;
         
     | 
| 
      
 140 
     | 
    
         
            +
                            }
         
     | 
| 
      
 141 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_SUPERSCRIPT)) => {
         
     | 
| 
      
 142 
     | 
    
         
            +
                                comrak_options.extension.superscript = TryConvert::try_convert(value)?;
         
     | 
| 
      
 143 
     | 
    
         
            +
                            }
         
     | 
| 
      
 144 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_HEADER_IDS)) => {
         
     | 
| 
      
 145 
     | 
    
         
            +
                                comrak_options.extension.header_ids = try_convert_string(value);
         
     | 
| 
      
 146 
     | 
    
         
            +
                            }
         
     | 
| 
      
 147 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_FOOTNOTES)) => {
         
     | 
| 
      
 148 
     | 
    
         
            +
                                comrak_options.extension.footnotes = TryConvert::try_convert(value)?;
         
     | 
| 
      
 149 
     | 
    
         
            +
                            }
         
     | 
| 
      
 150 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_DESCRIPTION_LISTS)) => {
         
     | 
| 
      
 151 
     | 
    
         
            +
                                comrak_options.extension.description_lists = TryConvert::try_convert(value)?;
         
     | 
| 
      
 152 
     | 
    
         
            +
                            }
         
     | 
| 
      
 153 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_FRONT_MATTER_DELIMITER)) => {
         
     | 
| 
      
 154 
     | 
    
         
            +
                                if let Some(option) = try_convert_string(value) {
         
     | 
| 
      
 155 
     | 
    
         
            +
                                    if !option.is_empty() {
         
     | 
| 
      
 156 
     | 
    
         
            +
                                        comrak_options.extension.front_matter_delimiter = Some(option);
         
     | 
| 
      
 157 
     | 
    
         
            +
                                    }
         
     | 
| 
      
 158 
     | 
    
         
            +
                                }
         
     | 
| 
      
 159 
     | 
    
         
            +
                            }
         
     | 
| 
      
 160 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_MULTILINE_BLOCK_QUOTES)) => {
         
     | 
| 
      
 161 
     | 
    
         
            +
                                comrak_options.extension.multiline_block_quotes =
         
     | 
| 
      
 162 
     | 
    
         
            +
                                    TryConvert::try_convert(value)?;
         
     | 
| 
      
 163 
     | 
    
         
            +
                            }
         
     | 
| 
      
 164 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_MATH_DOLLARS)) => {
         
     | 
| 
      
 165 
     | 
    
         
            +
                                comrak_options.extension.math_dollars = TryConvert::try_convert(value)?;
         
     | 
| 
      
 166 
     | 
    
         
            +
                            }
         
     | 
| 
      
 167 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_MATH_CODE)) => {
         
     | 
| 
      
 168 
     | 
    
         
            +
                                comrak_options.extension.math_code = TryConvert::try_convert(value)?;
         
     | 
| 
      
 169 
     | 
    
         
            +
                            }
         
     | 
| 
      
 170 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_SHORTCODES)) => {
         
     | 
| 
      
 171 
     | 
    
         
            +
                                comrak_options.extension.shortcodes = TryConvert::try_convert(value)?;
         
     | 
| 
      
 172 
     | 
    
         
            +
                            }
         
     | 
| 
      
 173 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_WIKILINKS_TITLE_AFTER_PIPE)) => {
         
     | 
| 
      
 174 
     | 
    
         
            +
                                comrak_options.extension.wikilinks_title_after_pipe =
         
     | 
| 
      
 175 
     | 
    
         
            +
                                    TryConvert::try_convert(value)?;
         
     | 
| 
      
 176 
     | 
    
         
            +
                            }
         
     | 
| 
      
 177 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_WIKILINKS_TITLE_BEFORE_PIPE)) => {
         
     | 
| 
      
 178 
     | 
    
         
            +
                                comrak_options.extension.wikilinks_title_before_pipe =
         
     | 
| 
      
 179 
     | 
    
         
            +
                                    TryConvert::try_convert(value)?;
         
     | 
| 
      
 180 
     | 
    
         
            +
                            }
         
     | 
| 
      
 181 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_UNDERLINE)) => {
         
     | 
| 
      
 182 
     | 
    
         
            +
                                comrak_options.extension.underline = TryConvert::try_convert(value)?;
         
     | 
| 
      
 183 
     | 
    
         
            +
                            }
         
     | 
| 
      
 184 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_SPOILER)) => {
         
     | 
| 
      
 185 
     | 
    
         
            +
                                comrak_options.extension.spoiler = TryConvert::try_convert(value)?;
         
     | 
| 
      
 186 
     | 
    
         
            +
                            }
         
     | 
| 
      
 187 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_GREENTEXT)) => {
         
     | 
| 
      
 188 
     | 
    
         
            +
                                comrak_options.extension.greentext = TryConvert::try_convert(value)?;
         
     | 
| 
      
 189 
     | 
    
         
            +
                            }
         
     | 
| 
      
 190 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_SUBSCRIPT)) => {
         
     | 
| 
      
 191 
     | 
    
         
            +
                                comrak_options.extension.subscript = TryConvert::try_convert(value)?;
         
     | 
| 
      
 192 
     | 
    
         
            +
                            }
         
     | 
| 
      
 193 
     | 
    
         
            +
                            Ok(Cow::Borrowed(EXTENSION_ALERTS)) => {
         
     | 
| 
      
 194 
     | 
    
         
            +
                                comrak_options.extension.alerts = TryConvert::try_convert(value)?;
         
     | 
| 
      
 195 
     | 
    
         
            +
                            }
         
     | 
| 
      
 196 
     | 
    
         
            +
                            _ => {}
         
     | 
| 
      
 197 
     | 
    
         
            +
                        }
         
     | 
| 
      
 198 
     | 
    
         
            +
                        Ok(ForEach::Continue)
         
     | 
| 
      
 199 
     | 
    
         
            +
                    })
         
     | 
| 
      
 200 
     | 
    
         
            +
                    .unwrap();
         
     | 
| 
      
 201 
     | 
    
         
            +
            }
         
     | 
| 
      
 202 
     | 
    
         
            +
             
     | 
| 
      
 203 
     | 
    
         
            +
            pub fn iterate_options_hash(
         
     | 
| 
      
 204 
     | 
    
         
            +
                comrak_options: &mut ComrakOptions,
         
     | 
| 
      
 205 
     | 
    
         
            +
                key: Symbol,
         
     | 
| 
      
 206 
     | 
    
         
            +
                value: RHash,
         
     | 
| 
      
 207 
     | 
    
         
            +
            ) -> Result<ForEach, Error> {
         
     | 
| 
      
 208 
     | 
    
         
            +
                assert!(value.is_kind_of(class::hash()));
         
     | 
| 
      
 209 
     | 
    
         
            +
             
     | 
| 
      
 210 
     | 
    
         
            +
                if key.name().unwrap() == "parse" {
         
     | 
| 
      
 211 
     | 
    
         
            +
                    iterate_parse_options(comrak_options, value);
         
     | 
| 
      
 212 
     | 
    
         
            +
                }
         
     | 
| 
      
 213 
     | 
    
         
            +
                if key.name().unwrap() == "render" {
         
     | 
| 
      
 214 
     | 
    
         
            +
                    iterate_render_options(comrak_options, value);
         
     | 
| 
      
 215 
     | 
    
         
            +
                }
         
     | 
| 
      
 216 
     | 
    
         
            +
                if key.name().unwrap() == "extension" {
         
     | 
| 
      
 217 
     | 
    
         
            +
                    iterate_extension_options(comrak_options, value);
         
     | 
| 
      
 218 
     | 
    
         
            +
                }
         
     | 
| 
      
 219 
     | 
    
         
            +
                Ok(ForEach::Continue)
         
     | 
| 
      
 220 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,166 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            use std::path::PathBuf;
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            use comrak::plugins::syntect::{SyntectAdapter, SyntectAdapterBuilder};
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            use magnus::value::ReprValue;
         
     | 
| 
      
 6 
     | 
    
         
            +
            use magnus::{exception, RHash, Symbol, TryConvert, Value};
         
     | 
| 
      
 7 
     | 
    
         
            +
            use syntect::highlighting::ThemeSet;
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            use crate::EMPTY_STR;
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            pub fn construct_syntax_highlighter_from_plugin(
         
     | 
| 
      
 12 
     | 
    
         
            +
                rb_plugins: Option<RHash>,
         
     | 
| 
      
 13 
     | 
    
         
            +
            ) -> Result<Option<SyntectAdapter>, magnus::Error> {
         
     | 
| 
      
 14 
     | 
    
         
            +
                match rb_plugins {
         
     | 
| 
      
 15 
     | 
    
         
            +
                    None => Ok(None),
         
     | 
| 
      
 16 
     | 
    
         
            +
                    Some(rb_plugins) => {
         
     | 
| 
      
 17 
     | 
    
         
            +
                        let theme = match rb_plugins.get(Symbol::new(super::SYNTAX_HIGHLIGHTER_PLUGIN)) {
         
     | 
| 
      
 18 
     | 
    
         
            +
                            Some(syntax_highlighter_options) => {
         
     | 
| 
      
 19 
     | 
    
         
            +
                                match fetch_syntax_highlighter_theme(syntax_highlighter_options) {
         
     | 
| 
      
 20 
     | 
    
         
            +
                                    Ok(theme) => theme,
         
     | 
| 
      
 21 
     | 
    
         
            +
                                    Err(e) => {
         
     | 
| 
      
 22 
     | 
    
         
            +
                                        return Err(e);
         
     | 
| 
      
 23 
     | 
    
         
            +
                                    }
         
     | 
| 
      
 24 
     | 
    
         
            +
                                }
         
     | 
| 
      
 25 
     | 
    
         
            +
                            }
         
     | 
| 
      
 26 
     | 
    
         
            +
                            None => None, // no `syntax_highlighter:` defined
         
     | 
| 
      
 27 
     | 
    
         
            +
                        };
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                        let adapter: SyntectAdapter;
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                        match theme {
         
     | 
| 
      
 32 
     | 
    
         
            +
                            None => Ok(None),
         
     | 
| 
      
 33 
     | 
    
         
            +
                            Some(theme) => {
         
     | 
| 
      
 34 
     | 
    
         
            +
                                if theme.is_empty() {
         
     | 
| 
      
 35 
     | 
    
         
            +
                                    // no theme? uss css classes
         
     | 
| 
      
 36 
     | 
    
         
            +
                                    adapter = SyntectAdapter::new(None);
         
     | 
| 
      
 37 
     | 
    
         
            +
                                    Ok(Some(adapter))
         
     | 
| 
      
 38 
     | 
    
         
            +
                                } else {
         
     | 
| 
      
 39 
     | 
    
         
            +
                                    let path =
         
     | 
| 
      
 40 
     | 
    
         
            +
                                        match rb_plugins.get(Symbol::new(super::SYNTAX_HIGHLIGHTER_PLUGIN)) {
         
     | 
| 
      
 41 
     | 
    
         
            +
                                            Some(syntax_highlighter_options) => {
         
     | 
| 
      
 42 
     | 
    
         
            +
                                                fetch_syntax_highlighter_path(syntax_highlighter_options)?
         
     | 
| 
      
 43 
     | 
    
         
            +
                                            }
         
     | 
| 
      
 44 
     | 
    
         
            +
                                            None => PathBuf::from("".to_string()), // no `syntax_highlighter:` defined
         
     | 
| 
      
 45 
     | 
    
         
            +
                                        };
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                                    if path.exists() {
         
     | 
| 
      
 48 
     | 
    
         
            +
                                        if !path.is_dir() {
         
     | 
| 
      
 49 
     | 
    
         
            +
                                            return Err(magnus::Error::new(
         
     | 
| 
      
 50 
     | 
    
         
            +
                                                exception::arg_error(),
         
     | 
| 
      
 51 
     | 
    
         
            +
                                                "`path` needs to be a directory",
         
     | 
| 
      
 52 
     | 
    
         
            +
                                            ));
         
     | 
| 
      
 53 
     | 
    
         
            +
                                        }
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                                        let builder = SyntectAdapterBuilder::new();
         
     | 
| 
      
 56 
     | 
    
         
            +
                                        let mut ts = ThemeSet::load_defaults();
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                                        match ts.add_from_folder(&path) {
         
     | 
| 
      
 59 
     | 
    
         
            +
                                            Ok(_) => {}
         
     | 
| 
      
 60 
     | 
    
         
            +
                                            Err(e) => {
         
     | 
| 
      
 61 
     | 
    
         
            +
                                                return Err(magnus::Error::new(
         
     | 
| 
      
 62 
     | 
    
         
            +
                                                    exception::arg_error(),
         
     | 
| 
      
 63 
     | 
    
         
            +
                                                    format!("failed to load theme set from path: {e}"),
         
     | 
| 
      
 64 
     | 
    
         
            +
                                                ));
         
     | 
| 
      
 65 
     | 
    
         
            +
                                            }
         
     | 
| 
      
 66 
     | 
    
         
            +
                                        }
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                                        // check if the theme exists in the dir
         
     | 
| 
      
 69 
     | 
    
         
            +
                                        match ts.themes.get(&theme) {
         
     | 
| 
      
 70 
     | 
    
         
            +
                                            Some(theme) => theme,
         
     | 
| 
      
 71 
     | 
    
         
            +
                                            None => {
         
     | 
| 
      
 72 
     | 
    
         
            +
                                                return Err(magnus::Error::new(
         
     | 
| 
      
 73 
     | 
    
         
            +
                                                    exception::arg_error(),
         
     | 
| 
      
 74 
     | 
    
         
            +
                                                    format!("theme `{}` does not exist", theme),
         
     | 
| 
      
 75 
     | 
    
         
            +
                                                ));
         
     | 
| 
      
 76 
     | 
    
         
            +
                                            }
         
     | 
| 
      
 77 
     | 
    
         
            +
                                        };
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                                        adapter = builder.theme_set(ts).theme(&theme).build();
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                                        Ok(Some(adapter))
         
     | 
| 
      
 82 
     | 
    
         
            +
                                    } else {
         
     | 
| 
      
 83 
     | 
    
         
            +
                                        // no path? default theme lookup
         
     | 
| 
      
 84 
     | 
    
         
            +
                                        ThemeSet::load_defaults()
         
     | 
| 
      
 85 
     | 
    
         
            +
                                            .themes
         
     | 
| 
      
 86 
     | 
    
         
            +
                                            .get(&theme)
         
     | 
| 
      
 87 
     | 
    
         
            +
                                            .ok_or_else(|| {
         
     | 
| 
      
 88 
     | 
    
         
            +
                                                magnus::Error::new(
         
     | 
| 
      
 89 
     | 
    
         
            +
                                                    exception::arg_error(),
         
     | 
| 
      
 90 
     | 
    
         
            +
                                                    format!("theme `{}` does not exist", theme),
         
     | 
| 
      
 91 
     | 
    
         
            +
                                                )
         
     | 
| 
      
 92 
     | 
    
         
            +
                                            })?;
         
     | 
| 
      
 93 
     | 
    
         
            +
                                        adapter = SyntectAdapter::new(Some(&theme));
         
     | 
| 
      
 94 
     | 
    
         
            +
                                        Ok(Some(adapter))
         
     | 
| 
      
 95 
     | 
    
         
            +
                                    }
         
     | 
| 
      
 96 
     | 
    
         
            +
                                }
         
     | 
| 
      
 97 
     | 
    
         
            +
                            }
         
     | 
| 
      
 98 
     | 
    
         
            +
                        }
         
     | 
| 
      
 99 
     | 
    
         
            +
                    }
         
     | 
| 
      
 100 
     | 
    
         
            +
                }
         
     | 
| 
      
 101 
     | 
    
         
            +
            }
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
            fn fetch_syntax_highlighter_theme(value: Value) -> Result<Option<String>, magnus::Error> {
         
     | 
| 
      
 104 
     | 
    
         
            +
                if value.is_nil() {
         
     | 
| 
      
 105 
     | 
    
         
            +
                    // `syntax_highlighter: nil`
         
     | 
| 
      
 106 
     | 
    
         
            +
                    return Ok(None);
         
     | 
| 
      
 107 
     | 
    
         
            +
                }
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
                let syntax_highlighter_plugin: RHash = match TryConvert::try_convert(value) {
         
     | 
| 
      
 110 
     | 
    
         
            +
                    Ok(plugin) => plugin, // `syntax_highlighter: { theme: "<something>" }`
         
     | 
| 
      
 111 
     | 
    
         
            +
                    Err(e) => {
         
     | 
| 
      
 112 
     | 
    
         
            +
                        // not a hash!
         
     | 
| 
      
 113 
     | 
    
         
            +
                        return Err(e);
         
     | 
| 
      
 114 
     | 
    
         
            +
                    }
         
     | 
| 
      
 115 
     | 
    
         
            +
                };
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
                if syntax_highlighter_plugin.is_nil() || syntax_highlighter_plugin.is_empty() {
         
     | 
| 
      
 118 
     | 
    
         
            +
                    return Err(magnus::Error::new(
         
     | 
| 
      
 119 
     | 
    
         
            +
                        magnus::exception::type_error(),
         
     | 
| 
      
 120 
     | 
    
         
            +
                        "theme cannot be blank hash",
         
     | 
| 
      
 121 
     | 
    
         
            +
                    ));
         
     | 
| 
      
 122 
     | 
    
         
            +
                }
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
                let theme_key = Symbol::new(super::SYNTAX_HIGHLIGHTER_PLUGIN_THEME_KEY);
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                match syntax_highlighter_plugin.get(theme_key) {
         
     | 
| 
      
 127 
     | 
    
         
            +
                    Some(theme) => {
         
     | 
| 
      
 128 
     | 
    
         
            +
                        if theme.is_nil() {
         
     | 
| 
      
 129 
     | 
    
         
            +
                            return Err(magnus::Error::new(
         
     | 
| 
      
 130 
     | 
    
         
            +
                                magnus::exception::type_error(),
         
     | 
| 
      
 131 
     | 
    
         
            +
                                "theme cannot be nil",
         
     | 
| 
      
 132 
     | 
    
         
            +
                            ));
         
     | 
| 
      
 133 
     | 
    
         
            +
                        }
         
     | 
| 
      
 134 
     | 
    
         
            +
                        Ok(TryConvert::try_convert(theme)?)
         
     | 
| 
      
 135 
     | 
    
         
            +
                    }
         
     | 
| 
      
 136 
     | 
    
         
            +
                    None => {
         
     | 
| 
      
 137 
     | 
    
         
            +
                        // `syntax_highlighter: { theme: nil }`
         
     | 
| 
      
 138 
     | 
    
         
            +
                        Ok(None)
         
     | 
| 
      
 139 
     | 
    
         
            +
                    }
         
     | 
| 
      
 140 
     | 
    
         
            +
                }
         
     | 
| 
      
 141 
     | 
    
         
            +
            }
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
            fn fetch_syntax_highlighter_path(value: Value) -> Result<PathBuf, magnus::Error> {
         
     | 
| 
      
 144 
     | 
    
         
            +
                if value.is_nil() {
         
     | 
| 
      
 145 
     | 
    
         
            +
                    // `syntax_highlighter: nil`
         
     | 
| 
      
 146 
     | 
    
         
            +
                    return Ok(PathBuf::from(EMPTY_STR));
         
     | 
| 
      
 147 
     | 
    
         
            +
                }
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
                let syntax_highlighter_plugin: RHash = TryConvert::try_convert(value)?;
         
     | 
| 
      
 150 
     | 
    
         
            +
                let path_key = Symbol::new(super::SYNTAX_HIGHLIGHTER_PLUGIN_PATH_KEY);
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
                match syntax_highlighter_plugin.get(path_key) {
         
     | 
| 
      
 153 
     | 
    
         
            +
                    Some(path) => {
         
     | 
| 
      
 154 
     | 
    
         
            +
                        if path.is_nil() {
         
     | 
| 
      
 155 
     | 
    
         
            +
                            // `syntax_highlighter: { path: nil }`
         
     | 
| 
      
 156 
     | 
    
         
            +
                            return Ok(PathBuf::from(EMPTY_STR));
         
     | 
| 
      
 157 
     | 
    
         
            +
                        }
         
     | 
| 
      
 158 
     | 
    
         
            +
                        let val: String = TryConvert::try_convert(path)?;
         
     | 
| 
      
 159 
     | 
    
         
            +
                        Ok(PathBuf::from(val))
         
     | 
| 
      
 160 
     | 
    
         
            +
                    }
         
     | 
| 
      
 161 
     | 
    
         
            +
                    None => {
         
     | 
| 
      
 162 
     | 
    
         
            +
                        // `syntax_highlighter: {  }`
         
     | 
| 
      
 163 
     | 
    
         
            +
                        Ok(PathBuf::from(EMPTY_STR))
         
     | 
| 
      
 164 
     | 
    
         
            +
                    }
         
     | 
| 
      
 165 
     | 
    
         
            +
                }
         
     | 
| 
      
 166 
     | 
    
         
            +
            }
         
     | 
    
        data/lib/commonmarker/config.rb
    CHANGED
    
    | 
         @@ -1,54 +1,106 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            module  
     | 
| 
       4 
     | 
    
         
            -
              # For Ruby::Enum, these must be classes, not modules
         
     | 
| 
      
 3 
     | 
    
         
            +
            module Commonmarker
         
     | 
| 
       5 
4 
     | 
    
         
             
              module Config
         
     | 
| 
       6 
     | 
    
         
            -
                #  
     | 
| 
       7 
     | 
    
         
            -
                 
     | 
| 
      
 5 
     | 
    
         
            +
                # For details, see
         
     | 
| 
      
 6 
     | 
    
         
            +
                # https://github.com/kivikakk/comrak/blob/162ef9354deb2c9b4a4e05be495aa372ba5bb696/src/main.rs#L201
         
     | 
| 
      
 7 
     | 
    
         
            +
                OPTIONS = {
         
     | 
| 
       8 
8 
     | 
    
         
             
                  parse: {
         
     | 
| 
       9 
     | 
    
         
            -
                     
     | 
| 
       10 
     | 
    
         
            -
                     
     | 
| 
       11 
     | 
    
         
            -
                     
     | 
| 
       12 
     | 
    
         
            -
                     
     | 
| 
       13 
     | 
    
         
            -
                    SMART: (1 << 10),
         
     | 
| 
       14 
     | 
    
         
            -
                    LIBERAL_HTML_TAG: (1 << 12),
         
     | 
| 
       15 
     | 
    
         
            -
                    FOOTNOTES: (1 << 13),
         
     | 
| 
       16 
     | 
    
         
            -
                    STRIKETHROUGH_DOUBLE_TILDE: (1 << 14),
         
     | 
| 
      
 9 
     | 
    
         
            +
                    smart: false,
         
     | 
| 
      
 10 
     | 
    
         
            +
                    default_info_string: "",
         
     | 
| 
      
 11 
     | 
    
         
            +
                    relaxed_tasklist_matching: false,
         
     | 
| 
      
 12 
     | 
    
         
            +
                    relaxed_autolinks: false,
         
     | 
| 
       17 
13 
     | 
    
         
             
                  }.freeze,
         
     | 
| 
       18 
14 
     | 
    
         
             
                  render: {
         
     | 
| 
       19 
     | 
    
         
            -
                     
     | 
| 
       20 
     | 
    
         
            -
                     
     | 
| 
       21 
     | 
    
         
            -
                     
     | 
| 
       22 
     | 
    
         
            -
                     
     | 
| 
       23 
     | 
    
         
            -
                     
     | 
| 
       24 
     | 
    
         
            -
                     
     | 
| 
       25 
     | 
    
         
            -
                     
     | 
| 
       26 
     | 
    
         
            -
                     
     | 
| 
       27 
     | 
    
         
            -
                     
     | 
| 
       28 
     | 
    
         
            -
                     
     | 
| 
       29 
     | 
    
         
            -
                     
     | 
| 
       30 
     | 
    
         
            -
                     
     | 
| 
       31 
     | 
    
         
            -
                    FULL_INFO_STRING: (1 << 16),
         
     | 
| 
      
 15 
     | 
    
         
            +
                    hardbreaks: true,
         
     | 
| 
      
 16 
     | 
    
         
            +
                    github_pre_lang: true,
         
     | 
| 
      
 17 
     | 
    
         
            +
                    full_info_string: false,
         
     | 
| 
      
 18 
     | 
    
         
            +
                    width: 80,
         
     | 
| 
      
 19 
     | 
    
         
            +
                    unsafe: false,
         
     | 
| 
      
 20 
     | 
    
         
            +
                    escape: false,
         
     | 
| 
      
 21 
     | 
    
         
            +
                    sourcepos: false,
         
     | 
| 
      
 22 
     | 
    
         
            +
                    escaped_char_spans: true,
         
     | 
| 
      
 23 
     | 
    
         
            +
                    ignore_setext: false,
         
     | 
| 
      
 24 
     | 
    
         
            +
                    ignore_empty_links: false,
         
     | 
| 
      
 25 
     | 
    
         
            +
                    gfm_quirks: false,
         
     | 
| 
      
 26 
     | 
    
         
            +
                    prefer_fenced: false,
         
     | 
| 
       32 
27 
     | 
    
         
             
                  }.freeze,
         
     | 
| 
       33 
     | 
    
         
            -
                   
     | 
| 
      
 28 
     | 
    
         
            +
                  extension: {
         
     | 
| 
      
 29 
     | 
    
         
            +
                    strikethrough: true,
         
     | 
| 
      
 30 
     | 
    
         
            +
                    tagfilter: true,
         
     | 
| 
      
 31 
     | 
    
         
            +
                    table: true,
         
     | 
| 
      
 32 
     | 
    
         
            +
                    autolink: true,
         
     | 
| 
      
 33 
     | 
    
         
            +
                    tasklist: true,
         
     | 
| 
      
 34 
     | 
    
         
            +
                    superscript: false,
         
     | 
| 
      
 35 
     | 
    
         
            +
                    header_ids: "",
         
     | 
| 
      
 36 
     | 
    
         
            +
                    footnotes: false,
         
     | 
| 
      
 37 
     | 
    
         
            +
                    description_lists: false,
         
     | 
| 
      
 38 
     | 
    
         
            +
                    front_matter_delimiter: "",
         
     | 
| 
      
 39 
     | 
    
         
            +
                    multiline_block_quotes: false,
         
     | 
| 
      
 40 
     | 
    
         
            +
                    math_dollars: false,
         
     | 
| 
      
 41 
     | 
    
         
            +
                    math_code: false,
         
     | 
| 
      
 42 
     | 
    
         
            +
                    shortcodes: true,
         
     | 
| 
      
 43 
     | 
    
         
            +
                    wikilinks_title_before_pipe: false,
         
     | 
| 
      
 44 
     | 
    
         
            +
                    wikilinks_title_after_pipe: false,
         
     | 
| 
      
 45 
     | 
    
         
            +
                    underline: false,
         
     | 
| 
      
 46 
     | 
    
         
            +
                    spoiler: false,
         
     | 
| 
      
 47 
     | 
    
         
            +
                    greentext: false,
         
     | 
| 
      
 48 
     | 
    
         
            +
                    subscript: false,
         
     | 
| 
      
 49 
     | 
    
         
            +
                    alerts: false,
         
     | 
| 
      
 50 
     | 
    
         
            +
                  }.freeze,
         
     | 
| 
      
 51 
     | 
    
         
            +
                  format: [:html].freeze,
         
     | 
| 
       34 
52 
     | 
    
         
             
                }.freeze
         
     | 
| 
       35 
53 
     | 
    
         | 
| 
      
 54 
     | 
    
         
            +
                PLUGINS = {
         
     | 
| 
      
 55 
     | 
    
         
            +
                  syntax_highlighter: {
         
     | 
| 
      
 56 
     | 
    
         
            +
                    theme: "base16-ocean.dark",
         
     | 
| 
      
 57 
     | 
    
         
            +
                    path: "",
         
     | 
| 
      
 58 
     | 
    
         
            +
                  },
         
     | 
| 
      
 59 
     | 
    
         
            +
                }
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
       36 
61 
     | 
    
         
             
                class << self
         
     | 
| 
       37 
     | 
    
         
            -
                   
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
                       
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
      
 62 
     | 
    
         
            +
                  include Commonmarker::Utils
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                  def process_options(options)
         
     | 
| 
      
 65 
     | 
    
         
            +
                    {
         
     | 
| 
      
 66 
     | 
    
         
            +
                      parse: process_parse_options(options[:parse].dup),
         
     | 
| 
      
 67 
     | 
    
         
            +
                      render: process_render_options(options[:render].dup),
         
     | 
| 
      
 68 
     | 
    
         
            +
                      extension: process_extension_options(options[:extension].dup),
         
     | 
| 
      
 69 
     | 
    
         
            +
                    }
         
     | 
| 
      
 70 
     | 
    
         
            +
                  end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                  def process_plugins(plugins)
         
     | 
| 
      
 73 
     | 
    
         
            +
                    {
         
     | 
| 
      
 74 
     | 
    
         
            +
                      syntax_highlighter: process_syntax_highlighter_plugin(plugins&.fetch(:syntax_highlighter, nil)),
         
     | 
| 
      
 75 
     | 
    
         
            +
                    }
         
     | 
| 
      
 76 
     | 
    
         
            +
                  end
         
     | 
| 
      
 77 
     | 
    
         
            +
                end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                [:parse, :render, :extension].each do |type|
         
     | 
| 
      
 80 
     | 
    
         
            +
                  define_singleton_method :"process_#{type}_options" do |options|
         
     | 
| 
      
 81 
     | 
    
         
            +
                    Commonmarker::Config::OPTIONS[type].each_with_object({}) do |(key, value), hash|
         
     | 
| 
      
 82 
     | 
    
         
            +
                      if options.nil? || !options.key?(key) # option not provided, use the default
         
     | 
| 
      
 83 
     | 
    
         
            +
                        hash[key] = value
         
     | 
| 
      
 84 
     | 
    
         
            +
                        next
         
     | 
| 
      
 85 
     | 
    
         
            +
                      end
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
                      if options[key].nil? # # option explicitly not included, remove it
         
     | 
| 
      
 88 
     | 
    
         
            +
                        options.delete(key)
         
     | 
| 
      
 89 
     | 
    
         
            +
                        next
         
     | 
| 
      
 90 
     | 
    
         
            +
                      end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                      hash[key] = fetch_kv(options, key, value, type)
         
     | 
| 
       48 
93 
     | 
    
         
             
                    end
         
     | 
| 
       49 
     | 
    
         
            -
                  rescue KeyError => e
         
     | 
| 
       50 
     | 
    
         
            -
                    raise TypeError, "option ':#{e.key}' does not exist for #{name}::OPTS[:#{type}]"
         
     | 
| 
       51 
94 
     | 
    
         
             
                  end
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
      
 95 
     | 
    
         
            +
                end
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
                define_singleton_method :process_syntax_highlighter_plugin do |options|
         
     | 
| 
      
 98 
     | 
    
         
            +
                  return if options.nil? # plugin explicitly nil, remove it
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                  raise TypeError, "Expected a Hash for syntax_highlighter plugin, got #{options.class}" unless options.is_a?(Hash)
         
     | 
| 
      
 101 
     | 
    
         
            +
                  raise TypeError, "Expected a Hash for syntax_highlighter plugin, got nothing" if options.empty?
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                  Commonmarker::Config::PLUGINS[:syntax_highlighter].merge(options)
         
     | 
| 
      
 104 
     | 
    
         
            +
                end
         
     | 
| 
       53 
105 
     | 
    
         
             
              end
         
     | 
| 
       54 
106 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,14 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            begin
         
     | 
| 
      
 4 
     | 
    
         
            +
              # native precompiled gems package shared libraries in <gem_dir>/lib/commonmarker/<ruby_version>
         
     | 
| 
      
 5 
     | 
    
         
            +
              # load the precompiled extension file
         
     | 
| 
      
 6 
     | 
    
         
            +
              ruby_version = /\d+\.\d+/.match(RUBY_VERSION)
         
     | 
| 
      
 7 
     | 
    
         
            +
              require_relative "#{ruby_version}/commonmarker"
         
     | 
| 
      
 8 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
      
 9 
     | 
    
         
            +
              # fall back to the extension compiled upon installation.
         
     | 
| 
      
 10 
     | 
    
         
            +
              # use "require" instead of "require_relative" because non-native gems will place C extension files
         
     | 
| 
      
 11 
     | 
    
         
            +
              # in Gem::BasicSpecification#extension_dir after compilation (during normal installation), which
         
     | 
| 
      
 12 
     | 
    
         
            +
              # is in $LOAD_PATH but not necessarily relative to this file (see nokogiri#2300)
         
     | 
| 
      
 13 
     | 
    
         
            +
              require "commonmarker/commonmarker"
         
     | 
| 
      
 14 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require "pp"
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
            module  
     | 
| 
      
 5 
     | 
    
         
            +
            module Commonmarker
         
     | 
| 
       6 
6 
     | 
    
         
             
              class Node
         
     | 
| 
       7 
7 
     | 
    
         
             
                module Inspect
         
     | 
| 
       8 
8 
     | 
    
         
             
                  PP_INDENT_SIZE = 2
         
     | 
| 
         @@ -16,9 +16,19 @@ module CommonMarker 
     | 
|
| 
       16 
16 
     | 
    
         
             
                    printer.group(PP_INDENT_SIZE, "#<#{self.class}(#{type}):", ">") do
         
     | 
| 
       17 
17 
     | 
    
         
             
                      printer.breakable
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
                      attrs = [ 
     | 
| 
      
 19 
     | 
    
         
            +
                      attrs = [
         
     | 
| 
      
 20 
     | 
    
         
            +
                        :source_position,
         
     | 
| 
      
 21 
     | 
    
         
            +
                        :string_content,
         
     | 
| 
      
 22 
     | 
    
         
            +
                        :url,
         
     | 
| 
      
 23 
     | 
    
         
            +
                        :title,
         
     | 
| 
      
 24 
     | 
    
         
            +
                        :header_level,
         
     | 
| 
      
 25 
     | 
    
         
            +
                        :list_type,
         
     | 
| 
      
 26 
     | 
    
         
            +
                        :list_start,
         
     | 
| 
      
 27 
     | 
    
         
            +
                        :list_tight,
         
     | 
| 
      
 28 
     | 
    
         
            +
                        :fence_info,
         
     | 
| 
      
 29 
     | 
    
         
            +
                      ].filter_map do |name|
         
     | 
| 
       20 
30 
     | 
    
         
             
                        [name, __send__(name)]
         
     | 
| 
       21 
     | 
    
         
            -
                      rescue  
     | 
| 
      
 31 
     | 
    
         
            +
                      rescue StandardError
         
     | 
| 
       22 
32 
     | 
    
         
             
                        nil
         
     | 
| 
       23 
33 
     | 
    
         
             
                      end.compact
         
     | 
| 
       24 
34 
     | 
    
         | 
| 
         @@ -34,7 +44,7 @@ module CommonMarker 
     | 
|
| 
       34 
44 
     | 
    
         
             
                          node = first_child
         
     | 
| 
       35 
45 
     | 
    
         
             
                          while node
         
     | 
| 
       36 
46 
     | 
    
         
             
                            children << node
         
     | 
| 
       37 
     | 
    
         
            -
                            node = node. 
     | 
| 
      
 47 
     | 
    
         
            +
                            node = node.next_sibling
         
     | 
| 
       38 
48 
     | 
    
         
             
                          end
         
     | 
| 
       39 
49 
     | 
    
         
             
                          printer.text("children=")
         
     | 
| 
       40 
50 
     | 
    
         
             
                          printer.pp(children)
         
     |