Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions QuickMD/QuickMD.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@
A1B2C3D401000482 /* InlineEmphasis.swift in Sources (Tests) */ = {isa = PBXBuildFile; fileRef = A1B2C3D400000480 /* InlineEmphasis.swift */; };
A1B2C3D4010000E0 /* HTMLImageSyntax.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C3D4000000E0 /* HTMLImageSyntax.swift */; };
A1B2C3D4010000E1 /* HTMLImageSyntax.swift in Sources (Tests) */ = {isa = PBXBuildFile; fileRef = A1B2C3D4000000E0 /* HTMLImageSyntax.swift */; };
A1B2C3D4010009E0 /* HTMLBlockSyntax.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C3D4000009E0 /* HTMLBlockSyntax.swift */; };
A1B2C3D4010009E1 /* HTMLBlockSyntax.swift in Sources (Tests) */ = {isa = PBXBuildFile; fileRef = A1B2C3D4000009E0 /* HTMLBlockSyntax.swift */; };
A1B2C3D4010000E2 /* HTMLImageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C3D4000000E1 /* HTMLImageTests.swift */; };
A1B2C3D4010009E2 /* HTMLBlockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C3D4000009E2 /* HTMLBlockTests.swift */; };
A1B2C3D40100004D /* FileWatchManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C3D400000049 /* FileWatchManager.swift */; };
A1B2C3D40100004E /* ExternalEditorManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C3D40000004A /* ExternalEditorManager.swift */; };
A1B2C3D40100004F /* ExternalEditorPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B2C3D40000004B /* ExternalEditorPickerView.swift */; };
Expand Down Expand Up @@ -394,7 +397,9 @@
A1B2C3D4000000A0 /* InlineSyntaxScanner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InlineSyntaxScanner.swift; sourceTree = "<group>"; };
A1B2C3D400000480 /* InlineEmphasis.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InlineEmphasis.swift; sourceTree = "<group>"; };
A1B2C3D4000000E0 /* HTMLImageSyntax.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTMLImageSyntax.swift; sourceTree = "<group>"; };
A1B2C3D4000009E0 /* HTMLBlockSyntax.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTMLBlockSyntax.swift; sourceTree = "<group>"; };
A1B2C3D4000000E1 /* HTMLImageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTMLImageTests.swift; sourceTree = "<group>"; };
A1B2C3D4000009E2 /* HTMLBlockTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTMLBlockTests.swift; sourceTree = "<group>"; };
A1B2C3D400000049 /* FileWatchManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileWatchManager.swift; sourceTree = "<group>"; };
A1B2C3D40000004A /* ExternalEditorManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExternalEditorManager.swift; sourceTree = "<group>"; };
A1B2C3D40000004B /* ExternalEditorPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExternalEditorPickerView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -460,6 +465,7 @@
A1B2C3D4000004A0 /* FootnoteTests.swift */,
A1B2C3D400000082 /* ImageLoadingTests.swift */,
A1B2C3D4000000E1 /* HTMLImageTests.swift */,
A1B2C3D4000009E2 /* HTMLBlockTests.swift */,
A1B2C3D4000000F0 /* HeadingLayoutTests.swift */,
A1B2C3D4000001B2 /* TableTextTests.swift */,
A1B2C3D400000221 /* FrontMatterTests.swift */,
Expand Down Expand Up @@ -535,6 +541,7 @@
A1B2C3D4000000A0 /* InlineSyntaxScanner.swift */,
A1B2C3D400000480 /* InlineEmphasis.swift */,
A1B2C3D4000000E0 /* HTMLImageSyntax.swift */,
A1B2C3D4000009E0 /* HTMLBlockSyntax.swift */,
A1B2C3D400000049 /* FileWatchManager.swift */,
A1B2C3D40000004A /* ExternalEditorManager.swift */,
A1B2C3D403000004 /* Views */,
Expand Down Expand Up @@ -799,6 +806,7 @@
A1B2C3D4010000A0 /* InlineSyntaxScanner.swift in Sources */,
A1B2C3D401000481 /* InlineEmphasis.swift in Sources */,
A1B2C3D4010000E0 /* HTMLImageSyntax.swift in Sources */,
A1B2C3D4010009E0 /* HTMLBlockSyntax.swift in Sources */,
A1B2C3D40100004D /* FileWatchManager.swift in Sources */,
A1B2C3D40100004E /* ExternalEditorManager.swift in Sources */,
A1B2C3D40100004F /* ExternalEditorPickerView.swift in Sources */,
Expand Down Expand Up @@ -867,6 +875,7 @@
A1B2C3D4010000A1 /* InlineSyntaxScanner.swift in Sources (Tests) */,
A1B2C3D401000482 /* InlineEmphasis.swift in Sources (Tests) */,
A1B2C3D4010000E1 /* HTMLImageSyntax.swift in Sources (Tests) */,
A1B2C3D4010009E1 /* HTMLBlockSyntax.swift in Sources (Tests) */,
A1B2C3D401000051 /* FileWatcherTests.swift in Sources */,
A1B2C3D401000052 /* FileWatchManager.swift in Sources (Tests) */,
A1B2C3D401000053 /* ExternalEditorManager.swift in Sources (Tests) */,
Expand Down Expand Up @@ -926,6 +935,7 @@
A1B2C3D401000083 /* ImageLoader.swift in Sources (Tests) */,
A1B2C3D401000084 /* ImageLoadingTests.swift in Sources */,
A1B2C3D4010000E2 /* HTMLImageTests.swift in Sources */,
A1B2C3D4010009E2 /* HTMLBlockTests.swift in Sources */,
A1B2C3D4010000C1 /* DocumentSelection.swift in Sources (Tests) */,
A1B2C3D4010001C1 /* SelectionRows.swift in Sources (Tests) */,
A1B2C3D4010002A1 /* VerticalRhythm.swift in Sources (Tests) */,
Expand Down
39 changes: 33 additions & 6 deletions QuickMD/QuickMD/BlockHeightMeasurer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,32 @@ enum BlockLayout {
}
}

// MARK: Container summaries (`<details>`)

/// A `<details>` summary row (`MarkdownBlock.opensContainer`): the
/// disclosure control, then the caption's text view beside it — never
/// under it, so the control is no part of the text (its cursor, clicks
/// and tooltip are its own). The measurer wraps the caption at
/// `textWidth`, the view gives the control `controlWidth`.
enum ContainerSummary {
/// The control's column at 100 % zoom.
static let controlWidth: CGFloat = 18

static func controlWidth(fontScale: CGFloat) -> CGFloat { controlWidth * fontScale }

/// The width the caption wraps at: the column less the control.
static func textWidth(contentWidth: CGFloat, fontScale: CGFloat) -> CGFloat {
BlockLayout.clampedWidth(contentWidth - min(controlWidth(fontScale: fontScale), contentWidth / 2))
}

/// The text width of `block`'s row: the summary's, or `textWidth`
/// for any other text row.
static func textWidth(of block: MarkdownBlock, textWidth: CGFloat, contentWidth: CGFloat,
fontScale: CGFloat) -> CGFloat {
block.opensContainer == nil ? textWidth : self.textWidth(contentWidth: contentWidth, fontScale: fontScale)
}
}

// MARK: Blockquotes

enum Quote {
Expand Down Expand Up @@ -782,9 +808,7 @@ struct MathRendering {
else { return blocks }
return blocks.map { block in
guard case .mathBlock(let latex) = block.content, !typesets(latex) else { return block }
return MarkdownBlock(id: block.id,
content: .codeBlock(code: latex, language: "latex"),
sourceLine: block.sourceLine, substitutesFormula: true)
return block.replacingContent(.codeBlock(code: latex, language: "latex"), substitutesFormula: true)
}
}
}
Expand Down Expand Up @@ -1994,7 +2018,8 @@ enum BlockHeightMeasurer {
from: attributed, hasInlineMath: hasMath,
theme: theme, fontScale: fontScale, math: engine)
converted[block.id] = ns
let ink = textInk(text: ns, width: textWidth)
let ink = textInk(text: ns, width: BlockLayout.ContainerSummary.textWidth(
of: block, textWidth: textWidth, contentWidth: contentWidth, fontScale: fontScale))
heights.append(ink.height)
kinds.append(.exact)
textEdges = .text(ink)
Expand Down Expand Up @@ -2301,7 +2326,8 @@ enum BlockHeightMeasurer {
// this string are still the right images and only the wrap
// has to be recomputed.
converted[block.id] = existing
let ink = textInk(text: existing, width: textWidth)
let ink = textInk(text: existing, width: BlockLayout.ContainerSummary.textWidth(
of: block, textWidth: textWidth, contentWidth: contentWidth, fontScale: fontScale))
heights[index] = ink.height
rhythm[index] = rhythmRow(block, edges: .text(ink))
continue
Expand All @@ -2314,7 +2340,8 @@ enum BlockHeightMeasurer {
from: attributed, hasInlineMath: hasMath,
theme: theme, fontScale: fontScale, math: math)
converted[block.id] = ns
let ink = textInk(text: ns, width: textWidth)
let ink = textInk(text: ns, width: BlockLayout.ContainerSummary.textWidth(
of: block, textWidth: textWidth, contentWidth: contentWidth, fontScale: fontScale))
heights[index] = ink.height
rhythm[index] = rhythmRow(block, edges: .text(ink))

Expand Down
2 changes: 2 additions & 0 deletions QuickMD/QuickMD/DocumentSelection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ enum DocumentCopyBuilder {
result.removeAttribute(.qmdInlineMathSource, range: full)
result.removeAttribute(.qmdDisplayMathSource, range: full)
result.removeAttribute(.qmdInlineMathDelimiter, range: full)
// A `<details>` summary's toggle is the view's, not a link to paste.
HTMLBlockSyntax.removeToggleLinks(from: result)
return DocumentCopyOutput(plain: result.string, rtf: result)
}

Expand Down
Loading
Loading