Skip to main content

HeadingDecl

Struct HeadingDecl 

Source
pub struct HeadingDecl {
Show 13 fields pub name: Name, pub level: u8, pub counter: Option<Name>, pub style: Option<Name>, pub within: Option<Within>, pub number_format: NumberTemplate, pub title_number_format: String, pub skip_toc: bool, pub run_in: bool, pub ref_kind: RefKind, pub label_types: Vec<String>, pub anchor_prefix: String, pub docs: String,
}
Expand description

The declaration of a heading kind.

A heading kind is a type of heading, such as a section, a subsection or an appendix. A heading kind has a name and a level. Its declaration also contains the settings for the numbering of its headings, for their listing in a table of contents, for run-in headings, and for the labels that its headings accept. The heading kinds of a registry are listed in HeadingsConfig::headings.

HeadingDecl::new creates a heading kind from a name and a level, with default values for all other fields. Each of these fields has a builder method of the same name that changes it.

The declaration of a heading kind does not list the commands with which its headings are written. These commands are declared separately, as HeadingCommand values in HeadingsConfig::commands, because headings of the same kind can be written with several commands.

§Examples

use flm_core::stdlib::features::headings::HeadingDecl;
use flm_core::stdlib::features::numbering::{NumberTemplate, Within};

// An appendix at the level of the sections, numbered A, B, C.
let appendix =
    HeadingDecl::new("appendix", 1).number_format(NumberTemplate::formats("#{Alph}"));
assert_eq!(
    appendix.counter.as_ref().map(|name| name.as_str()),
    Some("flm.headings.appendix")
);
assert_eq!(
    appendix.style.as_ref().map(|name| name.as_str()),
    Some("flm.headings.style.appendix")
);

// A heading kind that is never numbered and never listed in a table of
// contents.
let aside = HeadingDecl::new("aside", 3).no_counter().skip_toc(true);
assert!(aside.counter.is_none());

// A heading kind numbered within the sections, as in `2.1`. The `Within`
// value refers to the counter of the sections by its full name.
let sub = HeadingDecl::new("subsection", 2).within(Within::parent("flm.headings.section"));

Fields§

§name: Name

The name of the heading kind, such as section. The name identifies the heading kind in the attribute data-flm-heading of the HTML output and in the render option HeadingsLatexOptions. In settings data, the name is the key of the entry and not a field.

§level: u8

The level of the heading kind. Levels count from 0, and an outer heading has a smaller level than the headings inside it. The standard heading kinds have the levels 1 to 5, so a heading kind above the sections, such as a chapter, can have the level 0.

The Sectioning aspect returns the level. The HTML element of a heading corresponds to its level, unless another element is set with a render option. The format of a heading in plain text also depends on its level. Whether the heading kind is numbered depends on its level and on the setting HeadingNumbering.

§counter: Option<Name>

The counter in which the headings of this kind are counted, given by its full name. The default is flm.headings.<name> (COUNTER_PREFIX). None means that the heading kind is never numbered; no counter is then declared for it in the numbering feature.

§style: Option<Name>

The counter style with which the numbers of this heading kind are formatted. The default is flm.headings.style.<name> (STYLE_PREFIX). A heading kind with a counter must have a counter style. HeadingDecl::no_counter removes both the counter and the counter style.

§within: Option<Within>

The counter within which the counter of this heading kind is numbered, and how the number of that counter is written before the number of this heading kind. The default, None, means that the counter is not numbered within another counter. Counters are given by their full names, as in Within::parent("flm.headings.section").

§number_format: NumberTemplate

The format of the number of this heading kind, without the numbers of its parent counters, in the number-template language of NumberTemplate. The default is #{arabic}.

§title_number_format: String

The heading title template of this heading kind: the text written before the title of a numbered heading. The text is written in the template language (see the template language shared by features), and the placeholder #{number} stands for the number of the heading. The default is DEFAULT_TITLE_NUMBER_FORMAT (#{number}. ), so a numbered section reads 1. Introduction.

The template can contain words and markup around the number, as in Chapter~#{number}: . With #[bare]{number}, the number is written without the numbers of the parent counters. With #[Roman]{number}, the number of this heading kind is written in Roman numerals. The number itself has the role NUMBER_ROLE, with which it can be formatted in a stylesheet or a lowering rule. A template without a placeholder is allowed: the headings are then counted, but their numbers are not written. The template is not used for a heading that is not numbered.

The registry build fails if the template cannot be parsed, if it contains a placeholder other than number, or if number is written with a key that it does not accept. title describes the template in full.

§skip_toc: bool

Whether the headings of this kind are never listed in a table of contents. If true, the option toc of these headings has no effect. The default is false.

§run_in: bool

Whether the headings of this kind are run-in headings, set at the start of the paragraph that they introduce (see run-in headings). The default is false.

§ref_kind: RefKind

The reference kind of the reference point of a heading of this kind. The default is KIND (section).

§label_types: Vec<String>

The label types that a heading of this kind accepts. The default is LABEL_TYPES (sec and topic).

§anchor_prefix: String

The text at the start of the anchor of a heading of this kind that has no label. The default is ANCHOR_PREFIX (sec).

§docs: String

A description of the heading kind in one sentence, used in the description of its element value in the registry. The default is empty, and an empty description is replaced with A heading of level <level>..

Implementations§

Source§

impl HeadingDecl

Source

pub fn new(name: impl Into<Name>, level: u8) -> HeadingDecl

Returns the heading kind name at the level level, with the following default values of the other fields:

  • the counter flm.headings.<name> (COUNTER_PREFIX) and the counter style flm.headings.style.<name> (STYLE_PREFIX);
  • no counter within which the counter is numbered;
  • the number format #{arabic} and the heading title template DEFAULT_TITLE_NUMBER_FORMAT;
  • headings listed in a table of contents and set as blocks;
  • the reference kind KIND, the label types LABEL_TYPES and the anchor prefix ANCHOR_PREFIX;
  • an empty description.
Source

pub fn counter(self, counter: impl Into<Name>) -> HeadingDecl

Sets the counter of this heading kind to counter, given by its full name.

Source

pub fn no_counter(self) -> HeadingDecl

Removes the counter and the counter style of this heading kind. A heading kind without a counter is never numbered, and no counter is declared for it in the numbering feature.

Source

pub fn style(self, style: impl Into<Name>) -> HeadingDecl

Sets the counter style of this heading kind to style.

Source

pub fn within(self, within: Within) -> HeadingDecl

Sets the counter within which the counter of this heading kind is numbered (see the field within).

Source

pub fn number_format(self, number_format: NumberTemplate) -> HeadingDecl

Sets the format of the number of this heading kind.

Source

pub fn title_number_format(self, text: impl Into<String>) -> HeadingDecl

Sets the heading title template of this heading kind: the text written before the title of a numbered heading, in which #{number} stands for the number (see the field title_number_format).

Source

pub fn skip_toc(self, skip_toc: bool) -> HeadingDecl

Sets whether the headings of this kind are never listed in a table of contents.

Source

pub fn run_in(self, run_in: bool) -> HeadingDecl

Sets whether the headings of this kind are run-in headings.

Source

pub fn ref_kind(self, ref_kind: impl Into<RefKind>) -> HeadingDecl

Sets the reference kind of the reference point of a heading of this kind.

Source

pub fn label_types( self, types: impl IntoIterator<Item = impl Into<String>>, ) -> HeadingDecl

Sets the label types that a heading of this kind accepts.

Source

pub fn anchor_prefix(self, prefix: impl Into<String>) -> HeadingDecl

Sets the text at the start of the anchor of a heading of this kind that has no label.

Source

pub fn docs(self, docs: impl Into<String>) -> HeadingDecl

Sets the description of this heading kind (see the field docs). If the crate is built without its cargo feature docs, the text is discarded and the field stays empty.

Trait Implementations§

Source§

impl Clone for HeadingDecl

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HeadingDecl

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for HeadingDecl

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for HeadingDecl

Source§

impl JsonSchema for HeadingDecl

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl NamedEntry for HeadingDecl

In settings data, a heading kind is an entry of the map HeadingsConfig::headings, with the name of the heading kind as its key. The entry must contain the field level. The other fields are optional; a field that is left out has the value set by HeadingDecl::new.

Source§

fn read_entry(name: &str, data: Value) -> Result<HeadingDecl, String>

Reads the entry named name from data, the rest of the entry as written under that name. Read more
Source§

impl PartialEq for HeadingDecl

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for HeadingDecl

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for HeadingDecl

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> SettingsData for T

Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.