commonmarker 0.23.5 → 0.23.7.pre1
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.
Potentially problematic release.
This version of commonmarker might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/ext/commonmarker/autolink.c +34 -3
- data/ext/commonmarker/cmark-gfm_version.h +2 -2
- data/ext/commonmarker/inlines.c +29 -4
- data/lib/commonmarker/config.rb +15 -13
- data/lib/commonmarker/renderer.rb +1 -1
- data/lib/commonmarker/version.rb +1 -1
- data/lib/commonmarker.rb +27 -25
- metadata +5 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: f41f7e434edcc989547b4cc9d02007ae0eed60c393bd6f7ee8a288f139c6b537
         | 
| 4 | 
            +
              data.tar.gz: 1c92f108fb98a076cf403c9e643f8a10b96d8c7ef359293686a27173e1e70436
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ee9ef9c3ff7bcee7d054e1961ce402ddc067a082ea969752346b9642510473547f1fa8aea5e534b5113b7035ea8ddacdbb67c50e2490585bc3d1197d888ea4ac
         | 
| 7 | 
            +
              data.tar.gz: 74b8df6b443d787cb9ce7110e7cabc34d5a0233a865b8cb67839b9bf1b11b636c02cd107a119e4fc02ca1122d3e736b84fc3fba0a674f5bd17928e25e3c4e8cf
         | 
    
        data/ext/commonmarker/autolink.c
    CHANGED
    
    | @@ -269,6 +269,22 @@ static cmark_node *match(cmark_syntax_extension *ext, cmark_parser *parser, | |
| 269 269 | 
             
              // inline was finished in inlines.c.
         | 
| 270 270 | 
             
            }
         | 
| 271 271 |  | 
| 272 | 
            +
            static bool validate_protocol(char protocol[], uint8_t *data, int rewind) {
         | 
| 273 | 
            +
              size_t len = strlen(protocol);
         | 
| 274 | 
            +
             | 
| 275 | 
            +
              // Check that the protocol matches
         | 
| 276 | 
            +
              for (int i = 1; i <= len; i++) {
         | 
| 277 | 
            +
                if (data[-rewind - i] != protocol[len - i]) {
         | 
| 278 | 
            +
                  return false;
         | 
| 279 | 
            +
                }
         | 
| 280 | 
            +
              }
         | 
| 281 | 
            +
             | 
| 282 | 
            +
              char prev_char = data[-rewind - len - 1];
         | 
| 283 | 
            +
             | 
| 284 | 
            +
              // Make sure the character before the protocol is non-alphanumeric
         | 
| 285 | 
            +
              return !cmark_isalnum(prev_char);
         | 
| 286 | 
            +
            }
         | 
| 287 | 
            +
             | 
| 272 288 | 
             
            static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset, int depth) {
         | 
| 273 289 | 
             
              // postprocess_text can recurse very deeply if there is a very long line of
         | 
| 274 290 | 
             
              // '@' only.  Stop at a reasonable depth to ensure it cannot crash.
         | 
| @@ -278,6 +294,8 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset, | |
| 278 294 | 
             
              uint8_t *data = text->as.literal.data,
         | 
| 279 295 | 
             
                *at;
         | 
| 280 296 | 
             
              size_t size = text->as.literal.len;
         | 
| 297 | 
            +
              bool auto_mailto = true;
         | 
| 298 | 
            +
              bool is_xmpp = false;
         | 
| 281 299 | 
             
              int rewind, max_rewind,
         | 
| 282 300 | 
             
                  nb = 0, np = 0, ns = 0;
         | 
| 283 301 |  | 
| @@ -304,8 +322,18 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset, | |
| 304 322 | 
             
                if (strchr(".+-_", c) != NULL)
         | 
| 305 323 | 
             
                  continue;
         | 
| 306 324 |  | 
| 307 | 
            -
                if (c  | 
| 308 | 
            -
                   | 
| 325 | 
            +
                if (strchr(":", c) != NULL) {
         | 
| 326 | 
            +
                  if (validate_protocol("mailto:", data, rewind)) {
         | 
| 327 | 
            +
                    auto_mailto = false;
         | 
| 328 | 
            +
                    continue;
         | 
| 329 | 
            +
                  }
         | 
| 330 | 
            +
             | 
| 331 | 
            +
                  if (validate_protocol("xmpp:", data, rewind)) {
         | 
| 332 | 
            +
                    auto_mailto = false;
         | 
| 333 | 
            +
                    is_xmpp = true;
         | 
| 334 | 
            +
                    continue;
         | 
| 335 | 
            +
                  }
         | 
| 336 | 
            +
                }
         | 
| 309 337 |  | 
| 310 338 | 
             
                break;
         | 
| 311 339 | 
             
              }
         | 
| @@ -325,6 +353,8 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset, | |
| 325 353 | 
             
                  nb++;
         | 
| 326 354 | 
             
                else if (c == '.' && link_end < size - 1 && cmark_isalnum(data[link_end + 1]))
         | 
| 327 355 | 
             
                  np++;
         | 
| 356 | 
            +
                else if (c == '/' && is_xmpp)
         | 
| 357 | 
            +
                  continue;
         | 
| 328 358 | 
             
                else if (c != '-' && c != '_')
         | 
| 329 359 | 
             
                  break;
         | 
| 330 360 | 
             
              }
         | 
| @@ -347,7 +377,8 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset, | |
| 347 377 | 
             
              cmark_node *link_node = cmark_node_new_with_mem(CMARK_NODE_LINK, parser->mem);
         | 
| 348 378 | 
             
              cmark_strbuf buf;
         | 
| 349 379 | 
             
              cmark_strbuf_init(parser->mem, &buf, 10);
         | 
| 350 | 
            -
               | 
| 380 | 
            +
              if (auto_mailto)
         | 
| 381 | 
            +
                cmark_strbuf_puts(&buf, "mailto:");
         | 
| 351 382 | 
             
              cmark_strbuf_put(&buf, data - rewind, (bufsize_t)(link_end + rewind));
         | 
| 352 383 | 
             
              link_node->as.link.url = cmark_chunk_buf_detach(&buf);
         | 
| 353 384 |  | 
| @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            #ifndef CMARK_GFM_VERSION_H
         | 
| 2 2 | 
             
            #define CMARK_GFM_VERSION_H
         | 
| 3 3 |  | 
| 4 | 
            -
            #define CMARK_GFM_VERSION ((0 << 24) | (29 << 16) | (0 << 8) |  | 
| 5 | 
            -
            #define CMARK_GFM_VERSION_STRING "0.29.0.gfm. | 
| 4 | 
            +
            #define CMARK_GFM_VERSION ((0 << 24) | (29 << 16) | (0 << 8) | 6)
         | 
| 5 | 
            +
            #define CMARK_GFM_VERSION_STRING "0.29.0.gfm.6"
         | 
| 6 6 |  | 
| 7 7 | 
             
            #endif
         | 
    
        data/ext/commonmarker/inlines.c
    CHANGED
    
    | @@ -41,6 +41,8 @@ typedef struct bracket { | |
| 41 41 | 
             
              bool image;
         | 
| 42 42 | 
             
              bool active;
         | 
| 43 43 | 
             
              bool bracket_after;
         | 
| 44 | 
            +
              bool in_bracket_image0;
         | 
| 45 | 
            +
              bool in_bracket_image1;
         | 
| 44 46 | 
             
            } bracket;
         | 
| 45 47 |  | 
| 46 48 | 
             
            typedef struct subject{
         | 
| @@ -516,6 +518,8 @@ static void push_bracket(subject *subj, bool image, cmark_node *inl_text) { | |
| 516 518 | 
             
              bracket *b = (bracket *)subj->mem->calloc(1, sizeof(bracket));
         | 
| 517 519 | 
             
              if (subj->last_bracket != NULL) {
         | 
| 518 520 | 
             
                subj->last_bracket->bracket_after = true;
         | 
| 521 | 
            +
                b->in_bracket_image0 = subj->last_bracket->in_bracket_image0;
         | 
| 522 | 
            +
                b->in_bracket_image1 = subj->last_bracket->in_bracket_image1;
         | 
| 519 523 | 
             
              }
         | 
| 520 524 | 
             
              b->image = image;
         | 
| 521 525 | 
             
              b->active = true;
         | 
| @@ -524,6 +528,11 @@ static void push_bracket(subject *subj, bool image, cmark_node *inl_text) { | |
| 524 528 | 
             
              b->previous_delimiter = subj->last_delim;
         | 
| 525 529 | 
             
              b->position = subj->pos;
         | 
| 526 530 | 
             
              b->bracket_after = false;
         | 
| 531 | 
            +
              if (image) {
         | 
| 532 | 
            +
                b->in_bracket_image1 = true;
         | 
| 533 | 
            +
              } else {
         | 
| 534 | 
            +
                b->in_bracket_image0 = true;
         | 
| 535 | 
            +
              }
         | 
| 527 536 | 
             
              subj->last_bracket = b;
         | 
| 528 537 | 
             
            }
         | 
| 529 538 |  | 
| @@ -1254,6 +1263,17 @@ match: | |
| 1254 1263 | 
             
                  }
         | 
| 1255 1264 | 
             
                  opener = opener->previous;
         | 
| 1256 1265 | 
             
                }
         | 
| 1266 | 
            +
                bool in_bracket_image1 = false;
         | 
| 1267 | 
            +
                if (opener) {
         | 
| 1268 | 
            +
                  in_bracket_image1 = opener->in_bracket_image1;
         | 
| 1269 | 
            +
                }
         | 
| 1270 | 
            +
                bracket *opener2 = subj->last_bracket;
         | 
| 1271 | 
            +
                while (opener2 != opener) {
         | 
| 1272 | 
            +
                  if (opener2->image) {
         | 
| 1273 | 
            +
                    opener2->in_bracket_image1 = in_bracket_image1;
         | 
| 1274 | 
            +
                  }
         | 
| 1275 | 
            +
                  opener2 = opener2->previous;
         | 
| 1276 | 
            +
                }
         | 
| 1257 1277 | 
             
              }
         | 
| 1258 1278 |  | 
| 1259 1279 | 
             
              return NULL;
         | 
| @@ -1662,10 +1682,15 @@ cmark_chunk *cmark_inline_parser_get_chunk(cmark_inline_parser *parser) { | |
| 1662 1682 | 
             
            }
         | 
| 1663 1683 |  | 
| 1664 1684 | 
             
            int cmark_inline_parser_in_bracket(cmark_inline_parser *parser, int image) {
         | 
| 1665 | 
            -
               | 
| 1666 | 
            -
             | 
| 1667 | 
            -
             | 
| 1668 | 
            -
               | 
| 1685 | 
            +
              bracket *b = parser->last_bracket;
         | 
| 1686 | 
            +
              if (!b) {
         | 
| 1687 | 
            +
                return 0;
         | 
| 1688 | 
            +
              }
         | 
| 1689 | 
            +
              if (image != 0) {
         | 
| 1690 | 
            +
                return b->in_bracket_image1;
         | 
| 1691 | 
            +
              } else {
         | 
| 1692 | 
            +
                return b->in_bracket_image0;
         | 
| 1693 | 
            +
              }
         | 
| 1669 1694 | 
             
            }
         | 
| 1670 1695 |  | 
| 1671 1696 | 
             
            void cmark_node_unput(cmark_node *node, int n) {
         | 
    
        data/lib/commonmarker/config.rb
    CHANGED
    
    | @@ -33,20 +33,22 @@ module CommonMarker | |
| 33 33 | 
             
                  format: [:html, :xml, :commonmark, :plaintext].freeze,
         | 
| 34 34 | 
             
                }.freeze
         | 
| 35 35 |  | 
| 36 | 
            -
                 | 
| 37 | 
            -
                   | 
| 38 | 
            -
             | 
| 39 | 
            -
                     | 
| 40 | 
            -
             | 
| 41 | 
            -
                     | 
| 36 | 
            +
                class << self
         | 
| 37 | 
            +
                  def process_options(option, type)
         | 
| 38 | 
            +
                    case option
         | 
| 39 | 
            +
                    when Symbol
         | 
| 40 | 
            +
                      OPTS.fetch(type).fetch(option)
         | 
| 41 | 
            +
                    when Array
         | 
| 42 | 
            +
                      raise TypeError if option.none?
         | 
| 42 43 |  | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 44 | 
            +
                      # neckbearding around. the map will both check the opts and then bitwise-OR it
         | 
| 45 | 
            +
                      OPTS.fetch(type).fetch_values(*option).inject(0, :|)
         | 
| 46 | 
            +
                    else
         | 
| 47 | 
            +
                      raise TypeError, "option type must be a valid symbol or array of symbols within the #{name}::OPTS[:#{type}] context"
         | 
| 48 | 
            +
                    end
         | 
| 49 | 
            +
                  rescue KeyError => e
         | 
| 50 | 
            +
                    raise TypeError, "option ':#{e.key}' does not exist for #{name}::OPTS[:#{type}]"
         | 
| 47 51 | 
             
                  end
         | 
| 48 | 
            -
             | 
| 49 | 
            -
                  raise TypeError, "option ':#{e.key}' does not exist for #{name}::OPTS[:#{type}]"
         | 
| 50 | 
            -
                end
         | 
| 52 | 
            +
              end
         | 
| 51 53 | 
             
              end
         | 
| 52 54 | 
             
            end
         | 
    
        data/lib/commonmarker/version.rb
    CHANGED
    
    
    
        data/lib/commonmarker.rb
    CHANGED
    
    | @@ -12,32 +12,34 @@ begin | |
| 12 12 | 
             
              require "awesome_print"
         | 
| 13 13 | 
             
            rescue LoadError; end # rubocop:disable Lint/SuppressedException
         | 
| 14 14 | 
             
            module CommonMarker
         | 
| 15 | 
            -
               | 
| 16 | 
            -
               | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
                 | 
| 15 | 
            +
              class << self
         | 
| 16 | 
            +
                # Public:  Parses a Markdown string into an HTML string.
         | 
| 17 | 
            +
                #
         | 
| 18 | 
            +
                # text - A {String} of text
         | 
| 19 | 
            +
                # option - Either a {Symbol} or {Array of Symbol}s indicating the render options
         | 
| 20 | 
            +
                # extensions - An {Array of Symbol}s indicating the extensions to use
         | 
| 21 | 
            +
                #
         | 
| 22 | 
            +
                # Returns a {String} of converted HTML.
         | 
| 23 | 
            +
                def render_html(text, options = :DEFAULT, extensions = [])
         | 
| 24 | 
            +
                  raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
         | 
| 24 25 |  | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 26 | 
            +
                  opts = Config.process_options(options, :render)
         | 
| 27 | 
            +
                  Node.markdown_to_html(text.encode("UTF-8"), opts, extensions)
         | 
| 28 | 
            +
                end
         | 
| 28 29 |  | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 30 | 
            +
                # Public: Parses a Markdown string into a `document` node.
         | 
| 31 | 
            +
                #
         | 
| 32 | 
            +
                # string - {String} to be parsed
         | 
| 33 | 
            +
                # option - A {Symbol} or {Array of Symbol}s indicating the parse options
         | 
| 34 | 
            +
                # extensions - An {Array of Symbol}s indicating the extensions to use
         | 
| 35 | 
            +
                #
         | 
| 36 | 
            +
                # Returns the `document` node.
         | 
| 37 | 
            +
                def render_doc(text, options = :DEFAULT, extensions = [])
         | 
| 38 | 
            +
                  raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
         | 
| 38 39 |  | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 40 | 
            +
                  opts = Config.process_options(options, :parse)
         | 
| 41 | 
            +
                  text = text.encode("UTF-8")
         | 
| 42 | 
            +
                  Node.parse_document(text, text.bytesize, opts, extensions)
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
            end
         | 
| 43 45 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: commonmarker
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.23. | 
| 4 | 
            +
              version: 0.23.7.pre1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Garen Torikian
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire:
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2022- | 
| 12 | 
            +
            date: 2022-11-14 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: awesome_print
         | 
| @@ -251,11 +251,11 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 251 251 | 
             
                  version: '4.0'
         | 
| 252 252 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 253 253 | 
             
              requirements:
         | 
| 254 | 
            -
              - - " | 
| 254 | 
            +
              - - ">"
         | 
| 255 255 | 
             
                - !ruby/object:Gem::Version
         | 
| 256 | 
            -
                  version:  | 
| 256 | 
            +
                  version: 1.3.1
         | 
| 257 257 | 
             
            requirements: []
         | 
| 258 | 
            -
            rubygems_version: 3.3. | 
| 258 | 
            +
            rubygems_version: 3.3.7
         | 
| 259 259 | 
             
            signing_key:
         | 
| 260 260 | 
             
            specification_version: 4
         | 
| 261 261 | 
             
            summary: CommonMark parser and renderer. Written in C, wrapped in Ruby.
         |