Rename soft linebreak to justified linebreak

This commit is contained in:
Laurenz 2022-04-24 21:36:41 +02:00
parent 2791f59ce2
commit 2f33ad0e0a
7 changed files with 22 additions and 19 deletions

View File

@ -101,7 +101,7 @@ impl Eval for MarkupNode {
Ok(match self { Ok(match self {
Self::Space => Content::Space, Self::Space => Content::Space,
Self::Parbreak => Content::Parbreak, Self::Parbreak => Content::Parbreak,
Self::Linebreak(soft) => Content::Linebreak(*soft), Self::Linebreak(justified) => Content::Linebreak(*justified),
Self::Text(text) => Content::Text(text.clone()), Self::Text(text) => Content::Text(text.clone()),
Self::Quote(double) => Content::Quote(*double), Self::Quote(double) => Content::Quote(*double),
Self::Strong(strong) => strong.eval(ctx, scp)?, Self::Strong(strong) => strong.eval(ctx, scp)?,

View File

@ -168,8 +168,8 @@ pub struct LinebreakNode;
#[node] #[node]
impl LinebreakNode { impl LinebreakNode {
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
let soft = args.named("soft")?.unwrap_or(false); let justified = args.named("justified")?.unwrap_or(false);
Ok(Content::Linebreak(soft)) Ok(Content::Linebreak(justified))
} }
} }

View File

@ -39,8 +39,8 @@ use crate::util::EcoString;
pub enum Content { pub enum Content {
/// A word space. /// A word space.
Space, Space,
/// A forced line break. If soft (`true`), the preceding line can still be /// A forced line break. If `true`, the preceding line can still be
/// justified, if hard (`false`) not. /// justified, if `false` not.
Linebreak(bool), Linebreak(bool),
/// Horizontal spacing. /// Horizontal spacing.
Horizontal(Spacing), Horizontal(Spacing),
@ -234,7 +234,7 @@ impl Debug for Content {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self { match self {
Self::Space => f.pad("Space"), Self::Space => f.pad("Space"),
Self::Linebreak(soft) => write!(f, "Linebreak({soft})"), Self::Linebreak(justified) => write!(f, "Linebreak({justified})"),
Self::Horizontal(kind) => write!(f, "Horizontal({kind:?})"), Self::Horizontal(kind) => write!(f, "Horizontal({kind:?})"),
Self::Text(text) => write!(f, "Text({text:?})"), Self::Text(text) => write!(f, "Text({text:?})"),
Self::Quote(double) => write!(f, "Quote({double})"), Self::Quote(double) => write!(f, "Quote({double})"),
@ -397,8 +397,8 @@ impl<'a> Builder<'a> {
Content::Space => { Content::Space => {
self.par.weak(ParChild::Text(' '.into()), 0, styles); self.par.weak(ParChild::Text(' '.into()), 0, styles);
} }
Content::Linebreak(soft) => { Content::Linebreak(justified) => {
let c = if *soft { '\u{2028}' } else { '\n' }; let c = if *justified { '\u{2028}' } else { '\n' };
self.par.destructive(ParChild::Text(c.into()), styles); self.par.destructive(ParChild::Text(c.into()), styles);
} }
Content::Horizontal(kind) => { Content::Horizontal(kind) => {

View File

@ -62,7 +62,7 @@ impl Markup {
self.0.children().filter_map(|node| match node.kind() { self.0.children().filter_map(|node| match node.kind() {
NodeKind::Space(2 ..) => Some(MarkupNode::Parbreak), NodeKind::Space(2 ..) => Some(MarkupNode::Parbreak),
NodeKind::Space(_) => Some(MarkupNode::Space), NodeKind::Space(_) => Some(MarkupNode::Space),
NodeKind::Linebreak(s) => Some(MarkupNode::Linebreak(*s)), NodeKind::Linebreak(j) => Some(MarkupNode::Linebreak(*j)),
NodeKind::Text(s) => Some(MarkupNode::Text(s.clone())), NodeKind::Text(s) => Some(MarkupNode::Text(s.clone())),
NodeKind::Escape(c) => Some(MarkupNode::Text((*c).into())), NodeKind::Escape(c) => Some(MarkupNode::Text((*c).into())),
NodeKind::NonBreakingSpace => Some(MarkupNode::Text('\u{00A0}'.into())), NodeKind::NonBreakingSpace => Some(MarkupNode::Text('\u{00A0}'.into())),
@ -88,8 +88,8 @@ impl Markup {
pub enum MarkupNode { pub enum MarkupNode {
/// Whitespace containing less than two newlines. /// Whitespace containing less than two newlines.
Space, Space,
/// A forced line break. If soft (`\`, `true`), the preceding line can still /// A forced line break. If `true` (`\`), the preceding line can still be
/// be justified, if hard (`\+`, `false`) not. /// justified, if `false` (`\+`) not.
Linebreak(bool), Linebreak(bool),
/// A paragraph break: Two or more newlines. /// A paragraph break: Two or more newlines.
Parbreak, Parbreak,

View File

@ -588,8 +588,8 @@ pub enum NodeKind {
Space(usize), Space(usize),
/// A consecutive non-markup string. /// A consecutive non-markup string.
Text(EcoString), Text(EcoString),
/// A forced line break. If soft (`\`, `true`), the preceding line can still /// A forced line break. If `true` (`\`), the preceding line can still be
/// be justified, if hard (`\+`, `false`) not. /// justified, if `false` (`\+`) not.
Linebreak(bool), Linebreak(bool),
/// A non-breaking space: `~`. /// A non-breaking space: `~`.
NonBreakingSpace, NonBreakingSpace,
@ -867,8 +867,8 @@ impl NodeKind {
Self::Markup(_) => "markup", Self::Markup(_) => "markup",
Self::Space(2 ..) => "paragraph break", Self::Space(2 ..) => "paragraph break",
Self::Space(_) => "space", Self::Space(_) => "space",
Self::Linebreak(false) => "hard linebreak", Self::Linebreak(false) => "linebreak",
Self::Linebreak(true) => "soft linebreak", Self::Linebreak(true) => "justified linebreak",
Self::Text(_) => "text", Self::Text(_) => "text",
Self::NonBreakingSpace => "non-breaking space", Self::NonBreakingSpace => "non-breaking space",
Self::Shy => "soft hyphen", Self::Shy => "soft hyphen",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -13,7 +13,7 @@ Supercalifragilisticexpialidocious Expialigoricmetrioxidation.
This is partly emp#emph[has]ized. This is partly emp#emph[has]ized.
--- ---
Hard \ break. Hard #linebreak() break.
--- ---
// Test hard break directly after normal break. // Test hard break directly after normal break.
@ -21,13 +21,16 @@ Hard break directly after \ normal break.
--- ---
// Test consecutive breaks. // Test consecutive breaks.
Two consecutive \ \ breaks and three \ \ \ more. Two consecutive \ \ breaks and three \ \ more.
--- ---
// Test forcing an empty trailing line. // Test forcing an empty trailing line.
Trailing break \ \ Trailing break \ \
--- ---
// Test soft breaks. // Test justified breaks.
#set par(justify: true) #set par(justify: true)
With a soft \+ break you can force a break without breaking justification. With a soft \+
break you can force a break without #linebreak(justified: true)
breaking justification. #linebreak(justified: false)
Nice!