Title: Preserve literal ampersands in Markdown links and images by PHJ2000 · Pull Request #468 · commonmark/commonmark-java · GitHub
Open Graph Title: Preserve literal ampersands in Markdown links and images by PHJ2000 · Pull Request #468 · commonmark/commonmark-java
X Title: Preserve literal ampersands in Markdown links and images by PHJ2000 · Pull Request #468 · commonmark/commonmark-java
Description: Rendering a Link or Image whose destination/title contains literal entity-like text (for example © or A) writes an unescaped ampersand. Parsing that Markdown again turns the text into a character, changing the AST value. For example: import org.commonmark.node.*; import org.commonmark.parser.Parser; import org.commonmark.renderer.markdown.MarkdownRenderer; public class CommonmarkAmpersandProbe { public static void main(String[] args) { Link link = new Link("/url?value=©", "literal A"); link.appendChild(new Text("example")); String markdown = MarkdownRenderer.builder().build().render(link); Link reparsed = (Link) Parser.builder().build().parse(markdown).getFirstChild().getFirstChild(); if (!link.getDestination().equals(reparsed.getDestination()) || !link.getTitle().equals(reparsed.getTitle())) { throw new AssertionError("Changed to: " + reparsed.getDestination() + " / " + reparsed.getTitle()); } System.out.println(markdown); System.out.println("Literal destination and title preserved"); } } Use the existing MarkdownWriter escaping for ampersands in bare/angle-bracket destinations and quoted titles. The regression tests cover links and images, named/decimal/hex entities, angle-bracket destinations, and ordinary ampersands. Ordinary query separators are also escaped in the Markdown output, while the parsed values stay the same; the renderer does not promise identical Markdown syntax. Validation: Baseline: 14 of the 18 new parameter cases fail; the four ordinary-ampersand controls pass. JDK 21: focused renderer and spec tests pass; ./mvnw clean verify javadoc:javadoc spotless:check succeeds (4,603 test entries, 1 skipped, no failures/errors). Javadoc emits nonfatal missing sibling target/apidocs link messages; generation completes. Actual JDK 11: a standalone destination/title round-trip example compiles and runs. The separate Android project was not run. A separate AI review reproduced the 14 baseline failures and passing focused tests. It did not repeat the full reactor or JDK 11 probe. AI disclosure: OpenAI Codex assisted with investigation, implementation, tests, and this description. The separate review was also performed by an AI session, not a human reviewer.
Open Graph Description: Rendering a Link or Image whose destination/title contains literal entity-like text (for example © or A) writes an unescaped ampersand. Parsing that Markdown again turns the text i...
X Description: Rendering a Link or Image whose destination/title contains literal entity-like text (for example © or A) writes an unescaped ampersand. Parsing that Markdown again turns th...
Opengraph URL: https://github.com/commonmark/commonmark-java/pull/468
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:d6ee0959-926d-ac61-9449-148b57c352d4 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D55E:116DB0:14FB4D:1D0D8E:6AFBBC10 |
| html-safe-nonce | e9d51ccefed9761bb530a2b3ce50cec21926d1adb19da3c40d163490bc667b28 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENTVFOjExNkRCMDoxNEZCNEQ6MUQwRDhFOjZBRkJCQzEwIiwidmlzaXRvcl9pZCI6IjMwMjYyMjg2NDU2ODE5Mzc0MjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7f99c02e99d284e78118e8a0a60f03f5c91e9c9a0391175c6e991b166b19b2d3 |
| hovercard-subject-tag | pull_request:4982389078 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/commonmark/commonmark-java/pull/468/files |
| twitter:image | https://avatars.githubusercontent.com/u/105151063?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/105151063?s=400&v=4 |
| og:image:alt | Rendering a Link or Image whose destination/title contains literal entity-like text (for example © or A) writes an unescaped ampersand. Parsing that Markdown again turns the text i... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2b2ef9c1578c18d8ed27027940544c958743213cf4461659f14d3ccdf51e162c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/commonmark/commonmark-java git https://github.com/commonmark/commonmark-java.git |
| octolytics-dimension-user_id | 8661225 |
| octolytics-dimension-user_login | commonmark |
| octolytics-dimension-repository_id | 39477878 |
| octolytics-dimension-repository_nwo | commonmark/commonmark-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 39477878 |
| octolytics-dimension-repository_network_root_nwo | commonmark/commonmark-java |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e4cce0e99cf61481a318ff12c2e8580153a6c7c6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width