pub struct Paragraph {
pub runs: Vec<Run>,
pub para_shape_id: ParaShapeIndex,
pub column_break: bool,
pub page_break: bool,
pub heading_level: Option<u8>,
pub style_id: Option<StyleIndex>,
}Expand description
A paragraph: an ordered sequence of runs sharing a paragraph shape.
§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_core::run::Run;
use hwpforge_foundation::{CharShapeIndex, ParaShapeIndex};
let para = Paragraph::with_runs(
vec![Run::text("Hello", CharShapeIndex::new(0))],
ParaShapeIndex::new(0),
);
assert_eq!(para.run_count(), 1);
assert!(!para.is_empty());Fields§
§runs: Vec<Run>Ordered sequence of runs.
para_shape_id: ParaShapeIndexIndex into the paragraph shape collection (Blueprint resolves this).
column_break: boolWhether this paragraph starts a new column (HWPX columnBreak="1").
page_break: boolWhether this paragraph starts a new page (HWPX pageBreak="1").
heading_level: Option<u8>Optional heading level (1-7) for TOC participation.
Maps to 개요 1-7 styles. Paragraphs with a heading level
will emit <hp:titleMark> in HWPX for auto-TOC support.
style_id: Option<StyleIndex>Optional reference to a named style (e.g. 개요 1, 본문).
None means 바탕글 (style 0, the default).
Implementations§
Source§impl Paragraph
impl Paragraph
Sourcepub fn new(para_shape_id: ParaShapeIndex) -> Self
pub fn new(para_shape_id: ParaShapeIndex) -> Self
Creates an empty paragraph with the given shape reference.
§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_foundation::ParaShapeIndex;
let para = Paragraph::new(ParaShapeIndex::new(0));
assert!(para.is_empty());Sourcepub fn with_runs(runs: Vec<Run>, para_shape_id: ParaShapeIndex) -> Self
pub fn with_runs(runs: Vec<Run>, para_shape_id: ParaShapeIndex) -> Self
Creates a paragraph with pre-built runs.
§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_core::run::Run;
use hwpforge_foundation::{CharShapeIndex, ParaShapeIndex};
let para = Paragraph::with_runs(
vec![Run::text("text", CharShapeIndex::new(0))],
ParaShapeIndex::new(0),
);
assert_eq!(para.run_count(), 1);Sourcepub fn add_run(&mut self, run: Run)
pub fn add_run(&mut self, run: Run)
Appends a run to this paragraph.
§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_core::run::Run;
use hwpforge_foundation::{CharShapeIndex, ParaShapeIndex};
let mut para = Paragraph::new(ParaShapeIndex::new(0));
para.add_run(Run::text("hello", CharShapeIndex::new(0)));
assert_eq!(para.run_count(), 1);Sourcepub fn with_heading_level(self, level: u8) -> Self
pub fn with_heading_level(self, level: u8) -> Self
Sets the heading level for TOC participation (1-7).
Paragraphs with a heading level emit <hp:titleMark> in HWPX,
enabling 한글 to auto-build a Table of Contents from document headings.
§Panics
Panics if level is 0 or greater than 7.
§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_foundation::ParaShapeIndex;
let para = Paragraph::new(ParaShapeIndex::new(0))
.with_heading_level(1);
assert_eq!(para.heading_level, Some(1));Sourcepub fn with_style(self, style_id: StyleIndex) -> Self
pub fn with_style(self, style_id: StyleIndex) -> Self
Sets the style ID for this paragraph.
§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_foundation::{ParaShapeIndex, StyleIndex};
let para = Paragraph::new(ParaShapeIndex::new(0))
.with_style(StyleIndex::new(2));
assert_eq!(para.style_id, Some(StyleIndex::new(2)));Sourcepub fn with_page_break(self) -> Self
pub fn with_page_break(self) -> Self
Marks this paragraph as starting a new page (HWPX pageBreak="1").
§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_foundation::ParaShapeIndex;
let para = Paragraph::new(ParaShapeIndex::new(0)).with_page_break();
assert!(para.page_break);Sourcepub fn try_with_heading_level(self, level: u8) -> CoreResult<Self>
pub fn try_with_heading_level(self, level: u8) -> CoreResult<Self>
Sets the heading level for TOC participation (1-7), returning an error if the level is out of range.
This is the fallible alternative to with_heading_level,
suitable for user-supplied input where panicking is undesirable.
§Errors
Returns CoreError::InvalidStructure if level is 0 or greater than 7.
§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_foundation::ParaShapeIndex;
let para = Paragraph::new(ParaShapeIndex::new(0))
.try_with_heading_level(3)
.unwrap();
assert_eq!(para.heading_level, Some(3));
let err = Paragraph::new(ParaShapeIndex::new(0))
.try_with_heading_level(0);
assert!(err.is_err());Sourcepub fn text_content(&self) -> String
pub fn text_content(&self) -> String
Concatenates all text runs into a single string.
Non-text runs (Table, Image, Control) are silently skipped. This is useful for full-text search and preview generation.
§Examples
use hwpforge_core::paragraph::Paragraph;
use hwpforge_core::run::Run;
use hwpforge_core::table::Table;
use hwpforge_foundation::{CharShapeIndex, ParaShapeIndex};
let para = Paragraph::with_runs(
vec![
Run::text("Hello ", CharShapeIndex::new(0)),
Run::table(Table::new(vec![]), CharShapeIndex::new(0)),
Run::text("world", CharShapeIndex::new(0)),
],
ParaShapeIndex::new(0),
);
assert_eq!(para.text_content(), "Hello world");Trait Implementations§
Source§impl<'de> Deserialize<'de> for Paragraph
impl<'de> Deserialize<'de> for Paragraph
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for Paragraph
impl JsonSchema for Paragraph
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more