Repository: yshavit/mdq
Pull request #117 (2024-07-15 01:12:42)

`--link-canonicalization` -> `--link-format`
Change the flag name.


Patch:
diff --git a/src/fmt_md.rs b/src/fmt_md.rs
index a17f313..87debe0 100644
--- a/src/fmt_md.rs
+++ b/src/fmt_md.rs
@@ -95,7 +95,7 @@ where
             link_reference_placement: ReferencePlacement::Doc, // but we won't actually write them
             footnote_reference_placement: ReferencePlacement::Doc, // ditto
             inline_options: MdInlinesWriterOptions {
-                link_canonicalization: LinkTransform::Keep, // ignored; TODO remove from this struct
+                link_format: LinkTransform::Keep, // ignored; TODO remove from this struct
             },
         },
         prev_was_thematic_break: false,
@@ -1636,7 +1636,7 @@ pub mod tests {
                     link_reference_placement: ReferencePlacement::Section,
                     footnote_reference_placement: ReferencePlacement::Section,
                     inline_options: MdInlinesWriterOptions {
-                        link_canonicalization: LinkTransform::Reference,
+                        link_format: LinkTransform::Reference,
                     },
                 },
                 vec![MdElemRef::Link(&Link {
@@ -1720,7 +1720,7 @@ pub mod tests {
                     link_reference_placement: ReferencePlacement::Section,
                     footnote_reference_placement: ReferencePlacement::Section,
                     inline_options: MdInlinesWriterOptions {
-                        link_canonicalization: LinkTransform::Reference,
+                        link_format: LinkTransform::Reference,
                     },
                 },
                 vec![MdElemRef::Image(&Image {
@@ -1824,7 +1824,7 @@ pub mod tests {
                     link_reference_placement: ReferencePlacement::Section,
                     footnote_reference_placement: ReferencePlacement::Section,
                     inline_options: MdInlinesWriterOptions {
-                        link_canonicalization: LinkTransform::Keep,
+                        link_format: LinkTransform::Keep,
                     },
                 },
                 link_and_footnote_markdown(),
@@ -1851,7 +1851,7 @@ pub mod tests {
                     link_reference_placement: ReferencePlacement::Section,
                     footnote_reference_placement: ReferencePlacement::Doc,
                     inline_options: MdInlinesWriterOptions {
-                        link_canonicalization: LinkTransform::Keep,
+                        link_format: LinkTransform::Keep,
                     },
                 },
                 link_and_footnote_markdown(),
@@ -1881,7 +1881,7 @@ pub mod tests {
                     link_reference_placement: ReferencePlacement::Section,
                     footnote_reference_placement: ReferencePlacement::Section,
                     inline_options: MdInlinesWriterOptions {
-                        link_canonicalization: LinkTransform::Keep,
+                        link_format: LinkTransform::Keep,
                     },
                 },
                 md_elems![Paragraph {
@@ -1908,7 +1908,7 @@ pub mod tests {
                     link_reference_placement: ReferencePlacement::Doc,
                     footnote_reference_placement: ReferencePlacement::Section,
                     inline_options: MdInlinesWriterOptions {
-                        link_canonicalization: LinkTransform::Keep,
+                        link_format: LinkTransform::Keep,
                     },
                 },
                 link_and_footnote_markdown(),
@@ -1938,7 +1938,7 @@ pub mod tests {
                     link_reference_placement: ReferencePlacement::Doc,
                     footnote_reference_placement: ReferencePlacement::Doc,
                     inline_options: MdInlinesWriterOptions {
-                        link_canonicalization: LinkTransform::Keep,
+                        link_format: LinkTransform::Keep,
                     },
                 },
                 link_and_footnote_markdown(),
@@ -1967,7 +1967,7 @@ pub mod tests {
                     link_reference_placement: ReferencePlacement::Doc,
                     footnote_reference_placement: ReferencePlacement::Doc,
                     inline_options: MdInlinesWriterOptions {
-                        link_canonicalization: LinkTransform::Keep,
+                        link_format: LinkTransform::Keep,
                     },
                 },
                 // Define them in the opposite order that we'd expect them
@@ -2072,7 +2072,7 @@ pub mod tests {
             link_reference_placement: Default::default(),
             footnote_reference_placement: Default::default(),
             inline_options: MdInlinesWriterOptions {
-                link_canonicalization: LinkTransform::Keep,
+                link_format: LinkTransform::Keep,
             },
         }
     }
diff --git a/src/fmt_md_inlines.rs b/src/fmt_md_inlines.rs
index c326453..007e707 100644
--- a/src/fmt_md_inlines.rs
+++ b/src/fmt_md_inlines.rs
@@ -10,7 +10,7 @@ use std::collections::{HashMap, HashSet};
 
 #[derive(Debug, Copy, Clone)]
 pub struct MdInlinesWriterOptions {
-    pub link_canonicalization: LinkTransform,
+    pub link_format: LinkTransform,
 }
 
 pub struct MdInlinesWriter<'a> {
@@ -74,7 +74,7 @@ impl<'a> MdInlinesWriter<'a> {
             seen_links: HashSet::with_capacity(pending_refs_capacity),
             seen_footnotes: HashSet::with_capacity(pending_refs_capacity),
             pending_references: PendingReferences::with_capacity(pending_refs_capacity),
-            link_transformer: LinkTransformer::from(options.link_canonicalization),
+            link_transformer: LinkTransformer::from(options.link_format),
         }
     }
 
diff --git a/src/lib.rs b/src/lib.rs
index 28ef96e..d0e3ff8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -45,7 +45,7 @@ pub struct Cli {
     pub(crate) footnote_pos: Option<ReferencePlacement>,
 
     #[arg(long, short, value_enum, default_value_t=LinkTransform::Reference)]
-    pub(crate) link_canonicalization: LinkTransform, // TODO rename to link-format
+    pub(crate) link_format: LinkTransform,
 
     /// Output the results as a JSON object, instead of as markdown.
     #[arg(long, short, default_value_t = false)]
@@ -122,7 +122,7 @@ where
         link_reference_placement: cli.link_pos,
         footnote_reference_placement: cli.footnote_pos.unwrap_or(cli.link_pos),
         inline_options: MdInlinesWriterOptions {
-            link_canonicalization: cli.link_canonicalization,
+            link_format: cli.link_format,
         },
     };
 
diff --git a/src/link_transform.rs b/src/link_transform.rs
index 7006b5a..07bcdc5 100644
--- a/src/link_transform.rs
+++ b/src/link_transform.rs
@@ -43,7 +43,7 @@ impl<'a> Display for LinkLabel<'a> {
             LinkLabel::Text(s) => f.write_str(s),
             LinkLabel::Inline(inlines) => {
                 let mut inline_writer = MdInlinesWriter::new(MdInlinesWriterOptions {
-                    link_canonicalization: LinkTransform::Keep,
+                    link_format: LinkTransform::Keep,
                 });
                 f.write_str(&inlines_to_string(&mut inline_writer, *inlines))
             }
@@ -422,7 +422,7 @@ mod tests {
     fn smoke_test_multi() {
         let mut transformer = LinkTransformer::from(LinkTransform::Reference);
         let mut iw = MdInlinesWriter::new(MdInlinesWriterOptions {
-            link_canonicalization: LinkTransform::Keep,
+            link_format: LinkTransform::Keep,
         });
 
         // [alpha](https://example.com) ==> [alpha][1]
@@ -508,7 +508,7 @@ mod tests {
             } = self;
             let mut transformer = LinkTransformer::from(transform);
             let mut iw = MdInlinesWriter::new(MdInlinesWriterOptions {
-                link_canonicalization: LinkTransform::Keep,
+                link_format: LinkTransform::Keep,
             });
             let link = Link {
                 text: vec![label],
diff --git a/src/tree_ref_serde.rs b/src/tree_ref_serde.rs
index 5668c88..7a91c68 100644
--- a/src/tree_ref_serde.rs
+++ b/src/tree_ref_serde.rs
@@ -653,14 +653,14 @@ mod tests {
 
     fn check(given: MdElem, expect: &str) {
         let opts = MdInlinesWriterOptions {
-            link_canonicalization: LinkTransform::Keep,
+            link_format: LinkTransform::Keep,
         };
         check_with(opts, MdElemRef::from(&given), expect);
     }
 
     fn check_md_ref(given: MdElemRef, expect: &str) {
         let opts = MdInlinesWriterOptions {
-            link_canonicalization: LinkTransform::Keep,
+            link_format: LinkTransform::Keep,
         };
         check_with(opts, given, expect);
     }


Test patch:
diff --git a/tests/md_cases/links_references.toml b/tests/md_cases/links_references.toml
index 23a60c2..a44e5a7 100644
--- a/tests/md_cases/links_references.toml
+++ b/tests/md_cases/links_references.toml
@@ -41,7 +41,7 @@ output = '''
 
 
 [expect."keep original"]
-cli_args = ["--link-canonicalization", "keep"]
+cli_args = ["--link-format", "keep"]
 output = '''
 - an [inline link](https://example.com)
 - a [standard reference link][1]
@@ -61,7 +61,7 @@ output = '''
 
 
 [expect."inline all"]
-cli_args = ["--link-canonicalization", "inline"]
+cli_args = ["--link-format", "inline"]
 output = '''
 - an [inline link](https://example.com)
 - a [standard reference link](https://example.com/1)
diff --git a/tests/md_cases/select_link.toml b/tests/md_cases/select_link.toml
index 24ca110..365d0c1 100644
--- a/tests/md_cases/select_link.toml
+++ b/tests/md_cases/select_link.toml
@@ -9,7 +9,7 @@ This text has both [an inline link](https://example.com/inline) and a [reference
 
 
 [expect."select all"]
-cli_args = ['[]()', '--link-canonicalization=inline']
+cli_args = ['[]()', '--link-format=inline']
 output = '''
 [an inline link](https://example.com/inline)
 
@@ -19,19 +19,19 @@ output = '''
 
 
 [expect."select link by text"]
-cli_args = ['[an inline]()', '--link-canonicalization=inline']
+cli_args = ['[an inline]()', '--link-format=inline']
 output = '''
 [an inline link](https://example.com/inline)'''
 
 
 [expect."select link by url"]
-cli_args = ['[]("/referenced")', '--link-canonicalization=inline']
+cli_args = ['[]("/referenced")', '--link-format=inline']
 output = '''
 [referenced link](https://example.com/referenced)'''
 
 
 [expect."select image"]
-cli_args = ['![]()', '--link-canonicalization=inline']
+cli_args = ['![]()', '--link-format=inline']
 output = '''
 ![image alt text](https://example.com/hylas-and-nymphs.png)'''