3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-18 22:25:44 +01:00

Keep the link around a note in adfToPortableMarkdown, chosen in shown-text beside the image's

This commit is contained in:
2026-11-09 09:14:03 +01:00
committed by Lillem4n
parent 67e89da171
commit 2aa246898d
8 changed files with 51 additions and 31 deletions
+5 -6
View File
@@ -3,7 +3,7 @@ import type { LinkAttrs } from '../adf/mark-attributes.ts'
import { anchorOpener } from './anchor-element.ts'
import { languageClass } from './language-class.ts'
import { nodeAttrs, nodeContent } from '../adf/document.ts'
import { partsShownText, referenceName, shownImage, shownLink, shownText, shownUrl } from '../adf/shown-text.ts'
import { partsShownText, shownImage, shownLink, shownNote, shownText, shownUrl } from '../adf/shown-text.ts'
import { shownValue } from './escaping.ts'
// Compared by reference: each block makes one, so its content after a nested block starts a new shown block. `code`: this block, where it is a code block.
@@ -40,7 +40,7 @@ function shownPiece(node: AdfNode, lineFeed: string): string {
return linkedText(node, shownText(node), shownUrl(node), lineFeed)
}
// As portable markdown writes it inline, except that a link around a note stays (docs/decisions.md §The HTML dialect).
// As portable markdown writes it inline (docs/decisions.md §The HTML dialect).
function linkedImage(media: AdfNode, lineFeed: string): string {
const image = shownImage(media, shownLink(media)?.href)
const shown = linkedText(media, image?.text, image?.link, lineFeed)
@@ -48,11 +48,10 @@ function linkedImage(media: AdfNode, lineFeed: string): string {
}
function linkedText(node: AdfNode, standIn: string | undefined, url: string | undefined, lineFeed: string): string {
const link = shownLink(node) ?? (url === undefined ? undefined : { href: url })
const text = node.text ?? standIn
if (text !== undefined) return linked(shownValue(text, lineFeed), link)
const name = referenceName(node)
return name === undefined ? '' : linked(`<em>(${shownValue(name, lineFeed)})</em>`, link)
if (text !== undefined) return linked(shownValue(text, lineFeed), shownLink(node) ?? (url === undefined ? undefined : { href: url }))
const note = shownNote(node)
return note === undefined ? '' : linked(`<em>(${shownValue(note.name, lineFeed)})</em>`, note.link)
}
// The shown HTML inside an `<a>` where it links and HTML can hold the link.