gitlab-glfm-markdown 0.0.47 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e301cb75e5f8cfe5849701676319010a0ee73209942a80e084751202b0a65fb
4
- data.tar.gz: 5b888ebfe2f59c7f5489e899beefd5513066b74055f1609c759618267daef397
3
+ metadata.gz: 2473035d3bc69905f8f8287e2633cfa6dd36a0c38dc2e3d5488d9b85ddad4734
4
+ data.tar.gz: 274162e4643b6941c10ca13630421354218d4232171d0ce912cdb7bd2e81d5c9
5
5
  SHA512:
6
- metadata.gz: 9dc0786a85827e59c683e7ad2e46e1992dfcbbb4cf71150d55690d71a3c5a6ba873c97b3e9a0111b84dd1a15cddc90f693bd68dbdd7c3a9ca2bb8fb82b061916
7
- data.tar.gz: 9fca0669812cca3c3bfd290579dd9aeec0083382737005788d9b207a37f0a4038cf7cef4fb58ba281df0f739ac512a43260b9f778e0a54f38a140332f1fb825c
6
+ metadata.gz: f7d398e32754344e7b27603235961ca5f18a9ef67cf0387cf63954d059e76800c6923dc623cf7304d47aa55d6ad4927fb7f63249b1479cdc76e466ba3330e443
7
+ data.tar.gz: e930216bc4cebb0ff778d11bccc5baa6ea9740309f0078a7ede68b63c4747c0ff0f99883111c5b32bd05a1d408c0ba70e3e2e6cabab0b543ef3bc7a2c254928b
data/Cargo.lock CHANGED
@@ -220,9 +220,9 @@ checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
220
220
 
221
221
  [[package]]
222
222
  name = "comrak"
223
- version = "0.59.0"
223
+ version = "1.0.0"
224
224
  source = "registry+https://github.com/rust-lang/crates.io-index"
225
- checksum = "3adf553d37681e21753316065ad5a763d9513f81c910e250576c572114a8eb06"
225
+ checksum = "d981d666dca19afb3cc090dc7c381560cb8ba76582dda6e2c14686ff39fd547f"
226
226
  dependencies = [
227
227
  "caseless",
228
228
  "emojis",
@@ -345,7 +345,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
345
345
 
346
346
  [[package]]
347
347
  name = "gitlab-glfm-markdown"
348
- version = "0.0.47"
348
+ version = "0.1.0"
349
349
  dependencies = [
350
350
  "clap",
351
351
  "comrak",
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Latest Release](https://gitlab.com/gitlab-org/ruby/gems/gitlab-glfm-markdown/-/badges/release.svg)](https://gitlab.com/gitlab-org/ruby/gems/gitlab-glfm-markdown/-/releases)
5
5
 
6
6
  Implements GLFM (as used by GitLab) using the Rust-based Markdown parser
7
- [Comrak](https://github.com/kivikakk/comrak) (0.59.0), providing a Ruby interface.
7
+ [Comrak](https://github.com/kivikakk/comrak) (1.0.0), providing a Ruby interface.
8
8
 
9
9
  This project is still in constant flux, so interfaces and functionality can change at any time.
10
10
 
@@ -65,7 +65,7 @@ GLFMMarkdown.to_html('# header', options: { glfm: true, sourcepos: false })
65
65
  | `greentext` | Enable the `greentext` extension - requires at least one space after a `>` character to generate a blockquote, and restarts blockquote nesting across unique lines of input |
66
66
  | `hardbreaks` | Treat newlines as hard line breaks |
67
67
  | `header_accessibility` | Use new header/anchor combination in HTML output, per [!112](https://gitlab.com/gitlab-org/ruby/gems/gitlab-glfm-markdown/-/merge_requests/112). Requires `header_id_prefix` to be set. |
68
- | `header_id_prefix <PREFIX>` | Enable the `header-id` extension, with the given ID prefix |
68
+ | `header_id_prefix <PREFIX>` | Generate IDs for headings and description list terms with the given prefix. Use an empty string for unprefixed IDs. |
69
69
  | `header_id_prefix_in_href` | Include `header_id_prefix` in the heading anchor's `href`. Requires `header_id_prefix` to be set. |
70
70
  | `header_slug_prefix <PREFIX>` | Prefix to prepend to heading anchor slugs. When set, slugs become `{header_slug_prefix}{anchorized_text}`. Requires `header_accessibility` to be set. |
71
71
  | `ignore_empty_links` | Ignore empty links in input |
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "gitlab-glfm-markdown"
3
- version = "0.0.47"
3
+ version = "0.1.0"
4
4
  edition = "2021"
5
5
  authors = ["digitalmoksha <bwalker@gitlab.com>", "Asherah Connor <aconnor@gitlab.com>"]
6
6
  description = "GitLab Flavored Markdown parser and formatter. 100% CommonMark-compatible."
@@ -15,7 +15,7 @@ required-features = ["cli"]
15
15
 
16
16
  [dependencies]
17
17
  clap = { version = "=4.4.18", optional = true, features = ["derive", "string"] }
18
- comrak = { version = "0.59.0", default-features = false, features = ["shortcodes"] }
18
+ comrak = { version = "1", default-features = false, features = ["shortcodes"] }
19
19
  magnus = "0.8.2"
20
20
  rb-sys = { version = "0.9.124", default-features = false, features = ["stable-api-compiled-fallback"] }
21
21
  regex = "1.11.1"
@@ -72,6 +72,9 @@ create_formatter!(CustomFormatter<RenderUserData>, {
72
72
  NodeValue::Heading(ref nh) => |context, node, entering| {
73
73
  return render_heading(context, node, entering, nh);
74
74
  },
75
+ NodeValue::DescriptionTerm => |context, node, entering| {
76
+ return render_description_term(context, node, entering);
77
+ },
75
78
  });
76
79
 
77
80
  fn render_text(
@@ -142,6 +145,7 @@ fn render_link(
142
145
  if !nl.title.is_empty() {
143
146
  context.write_str(" title=\"")?;
144
147
  context.escape(&nl.title)?;
148
+ context.write_str("\"")?;
145
149
  }
146
150
 
147
151
  // This path only taken if placeholder detection is enabled, and the regex matched.
@@ -378,7 +382,7 @@ fn render_table_cell<T>(
378
382
  };
379
383
  let row = &row_node.data().value;
380
384
  let in_header = match *row {
381
- NodeValue::TableRow(header) => header,
385
+ NodeValue::TableRow(ref ntr) => ntr.header,
382
386
  _ => panic!("rendered a table cell contained by something other than a table row"),
383
387
  };
384
388
 
@@ -487,13 +491,7 @@ fn render_heading(
487
491
  write!(context, "<h{}", nh.level)?;
488
492
 
489
493
  if let Some(ref prefix) = context.options.extension.header_id_prefix {
490
- let text_content = node.collect_text();
491
- let id = context.anchorizer.anchorize(&text_content);
492
- let id = if let Some(ref slug_prefix) = context.user.header_slug_prefix {
493
- format!("{slug_prefix}{id}")
494
- } else {
495
- id
496
- };
494
+ let id = anchor_slug(context, node);
497
495
  write!(context, r##" id="{prefix}{id}""##)?;
498
496
  context.user.last_heading = Some(id);
499
497
  }
@@ -523,6 +521,39 @@ fn render_heading(
523
521
  Ok(ChildRendering::HTML)
524
522
  }
525
523
 
524
+ fn render_description_term(
525
+ context: &mut Context<RenderUserData>,
526
+ node: Node<'_>,
527
+ entering: bool,
528
+ ) -> Result<ChildRendering, fmt::Error> {
529
+ let (true, Some(prefix)) = (entering, &context.options.extension.header_id_prefix) else {
530
+ return format_node_default(context, node, entering);
531
+ };
532
+
533
+ let slug = anchor_slug(context, node);
534
+ context.write_str(r#"<dt id=""#)?;
535
+ context.escape(prefix)?;
536
+ context.escape(&slug)?;
537
+ context.write_str("\"")?;
538
+ render_sourcepos(context, node)?;
539
+ context.write_str(">")?;
540
+
541
+ Ok(ChildRendering::HTML)
542
+ }
543
+
544
+ fn anchor_slug(context: &mut Context<RenderUserData>, node: Node<'_>) -> String {
545
+ let slug = context.anchorizer.anchorize(&node.collect_text());
546
+ match context
547
+ .user
548
+ .header_slug_prefix
549
+ .as_ref()
550
+ .filter(|_| context.user.header_accessibility)
551
+ {
552
+ Some(prefix) => format!("{prefix}{slug}"),
553
+ None => slug,
554
+ }
555
+ }
556
+
526
557
  /// If the given node has a single text child, apply a function to the text content
527
558
  /// of that node. Otherwise, return the given default value.
528
559
  fn with_node_text_content<U, F>(node: Node<'_>, default: U, f: F) -> U
@@ -122,22 +122,31 @@ impl From<&RenderOptions> for comrak::Options<'_> {
122
122
  }
123
123
 
124
124
  pub fn render(text: &str, options: &RenderOptions) -> String {
125
- render_with_plugins(text, options, &Plugins::default())
125
+ render_with_plugins(
126
+ text,
127
+ options,
128
+ &comrak::Options::from(options),
129
+ &Plugins::default(),
130
+ )
126
131
  }
127
132
 
128
- fn render_with_plugins(text: &str, render_options: &RenderOptions, plugins: &Plugins) -> String {
133
+ pub fn render_with_plugins(
134
+ text: &str,
135
+ render_options: &RenderOptions,
136
+ options: &comrak::Options,
137
+ plugins: &Plugins,
138
+ ) -> String {
129
139
  let user_data = RenderUserData::from(render_options);
130
- let options = comrak::Options::from(render_options);
131
140
 
132
141
  if user_data.default_html {
133
- return comrak::markdown_to_html_with_plugins(text, &options, plugins);
142
+ return comrak::markdown_to_html_with_plugins(text, options, plugins);
134
143
  }
135
144
 
136
145
  let arena = Arena::new();
137
- let root = parse_document(&arena, text, &options);
146
+ let root = parse_document(&arena, text, options);
138
147
 
139
148
  let mut out = String::new();
140
- CustomFormatter::format_document_with_plugins(root, &options, &mut out, plugins, user_data)
149
+ CustomFormatter::format_document_with_plugins(root, options, &mut out, plugins, user_data)
141
150
  .unwrap();
142
151
  out
143
152
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GLFMMarkdown
4
- VERSION = '0.0.47'
4
+ VERSION = '0.1.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-glfm-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.47
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Walker
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2026-10-26 00:00:00.000000000 Z
12
+ date: 2026-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rb_sys