<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
  "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
[
<!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
<!ENTITY version SYSTEM "version.xml">
]>
<refentry id="pango-Markup">
<refmeta>
<refentrytitle role="top_of_page" id="pango-Markup.top_of_page">Markup</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>PANGO Library</refmiscinfo>
</refmeta>
<refnamediv>
<refname>Markup</refname>
<refpurpose>Simple markup language for text with attributes</refpurpose>
</refnamediv>

<refsect1 id="pango-Markup.functions" role="functions_proto">
<title role="functions_proto.title">Functions</title>
<informaltable pgwide="1" frame="none">
<tgroup cols="2">
<colspec colname="functions_proto_type" colwidth="150px"/>
<colspec colname="functions_proto_name"/>
<tbody>
<row><entry role="function_type"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
</entry><entry role="function_name"><link linkend="pango-parse-markup">pango_parse_markup</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="GMarkupParseContext"><returnvalue>GMarkupParseContext</returnvalue></link>&#160;*
</entry><entry role="function_name"><link linkend="pango-markup-parser-new">pango_markup_parser_new</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
</entry><entry role="function_name"><link linkend="pango-markup-parser-finish">pango_markup_parser_finish</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>


<refsect1 id="pango-Markup.description" role="desc">
<title role="desc.title">Description</title>
<para>Frequently, you want to display some text to the user with attributes
applied to part of the text (for example, you might want bold or
italicized words). With the base Pango interfaces, you could create a
<link linkend="PangoAttrList"><type>PangoAttrList</type></link> and apply it to the text; the problem is that you'd
need to apply attributes to some numeric range of characters, for
example "characters 12-17." This is broken from an internationalization
standpoint; once the text is translated, the word you wanted to
italicize could be in a different position.</para>
<para>The solution is to include the text attributes in the string to be
translated. Pango provides this feature with a small markup language.
You can parse a marked-up string into the string text plus a
<link linkend="PangoAttrList"><type>PangoAttrList</type></link> using either of <link linkend="pango-parse-markup"><function>pango_parse_markup()</function></link> or
<link linkend="pango-markup-parser-new"><function>pango_markup_parser_new()</function></link>.</para>
<para>A simple example of a marked-up string might be:</para>
<informalexample><programlisting role="example"><![CDATA[
<span foreground="blue" size="x-large">Blue text</span> is <i>cool</i>!
]]></programlisting></informalexample>
<para></para>
<para>Pango uses <link linkend="GMarkup"><type>GMarkup</type></link> to parse this language, which means that XML
features such as numeric character entities such as <literal>&amp;amp;#169;</literal> for
© can be used too.</para>
<para>The root tag of a marked-up document is <literal>&lt;markup&gt;</literal>, but
<link linkend="pango-parse-markup"><function>pango_parse_markup()</function></link> allows you to omit this tag, so you will most
likely never need to use it. The most general markup tag is <literal>&lt;span&gt;</literal>,
then there are some convenience tags.</para>
<refsect3><title>Span attributes</title><para><literal>&lt;span&gt;</literal> has the following attributes:</para>
<itemizedlist>
<listitem>
<para><literal>font_desc</literal>:
A font description string, such as "Sans Italic 12".
See <link linkend="pango-font-description-from-string"><function>pango_font_description_from_string()</function></link> for a description of the
format of the string representation . Note that any other span
attributes will override this description. So if you have "Sans Italic"
and also a <literal>style="normal"</literal> attribute, you will get Sans normal,
not italic.</para>
</listitem>
<listitem>
<para><literal>font_family</literal>:
A font family name</para>
</listitem>
<listitem>
<para><literal>font_size</literal>, <literal>size</literal>:
Font size in 1024ths of a point, or one of the absolute
sizes <literal>xx-small</literal>, <literal>x-small</literal>, <literal>small</literal>, <literal>medium</literal>, <literal>large</literal>,
<literal>x-large</literal>, <literal>xx-large</literal>, or one of the relative sizes <literal>smaller</literal>
or <literal>larger</literal>. If you want to specify a absolute size, it's usually
easier to take advantage of the ability to specify a partial
font description using <literal>font</literal>; you can use <literal>font='12.5'</literal>
rather than <literal>size='12800'</literal>.</para>
</listitem>
<listitem>
<para><literal>font_style</literal>:
One of <literal>normal</literal>, <literal>oblique</literal>, <literal>italic</literal></para>
</listitem>
<listitem>
<para><literal>font_weight</literal>:
One of <literal>ultralight</literal>, <literal>light</literal>, <literal>normal</literal>, <literal>bold</literal>,
<literal>ultrabold</literal>, <literal>heavy</literal>, or a numeric weight</para>
</listitem>
<listitem>
<para><literal>font_variant</literal>:
One of <literal>normal</literal> or <literal>smallcaps</literal></para>
</listitem>
<listitem>
<para><literal>font_stretch</literal>, <literal>stretch</literal>:
One of <literal>ultracondensed</literal>, <literal>extracondensed</literal>, <literal>condensed</literal>,
<literal>semicondensed</literal>, <literal>normal</literal>, <literal>semiexpanded</literal>, <literal>expanded</literal>,
<literal>extraexpanded</literal>, <literal>ultraexpanded</literal></para>
</listitem>
<listitem>
<para><literal>font_features</literal>:
A comma-separated list of OpenType font feature
settings, in the same syntax as accepted by CSS. E.g:
<literal>font_features='dlig=1, -kern, afrc on'</literal></para>
</listitem>
<listitem>
<para><literal>foreground</literal>, <literal>fgcolor</literal>:
An RGB color specification such as <literal>#00FF00</literal> or a color
name such as <literal>red</literal>. Since 1.38, an RGBA color specification such
as <literal>#00FF007F</literal> will be interpreted as specifying both a foreground
color and foreground alpha.</para>
</listitem>
<listitem>
<para><literal>background</literal>, <literal>bgcolor</literal>:
An RGB color specification such as <literal>#00FF00</literal> or a color
name such as <literal>red</literal>.
Since 1.38, an RGBA color specification such as <literal>#00FF007F</literal> will
be interpreted as specifying both a background color and
background alpha.</para>
</listitem>
<listitem>
<para><literal>alpha</literal>, <literal>fgalpha</literal>:
An alpha value for the foreground color, either a plain
integer between 1 and 65536 or a percentage value like <literal>50%</literal>.</para>
</listitem>
<listitem>
<para><literal>background_alpha</literal>, <literal>bgalpha</literal>:
An alpha value for the background color, either a plain
integer between 1 and 65536 or a percentage value like <literal>50%</literal>.</para>
</listitem>
<listitem>
<para><literal>underline</literal>:
One of <literal>none</literal>, <literal>single</literal>, <literal>double</literal>, <literal>low</literal>, <literal>error</literal>,
<literal>single-line</literal>, <literal>double-line</literal> or <literal>error-line</literal>.</para>
</listitem>
<listitem>
<para><literal>underline_color</literal>:
The color of underlines; an RGB color
specification such as <literal>#00FF00</literal> or a color name such as <literal>red</literal></para>
</listitem>
<listitem>
<para><literal>overline</literal>:
One of <literal>none</literal> or <literal>single</literal></para>
</listitem>
<listitem>
<para><literal>overline_color</literal>:
The color of overlines; an RGB color
specification such as <literal>#00FF00</literal> or a color name such as <literal>red</literal></para>
</listitem>
<listitem>
<para><literal>rise</literal>:
Vertical displacement, in Pango units. Can be negative for
subscript, positive for superscript.</para>
</listitem>
<listitem>
<para><literal>strikethrough</literal>
<literal>true</literal> or <literal>false</literal> whether to strike through the text</para>
</listitem>
<listitem>
<para><literal>strikethrough_color</literal>:
The color of strikethrough lines; an RGB
color specification such as <literal>#00FF00</literal> or a color name such as <literal>red</literal></para>
</listitem>
<listitem>
<para><literal>fallback</literal>:
<literal>true</literal> or <literal>false</literal> whether to enable fallback. If
disabled, then characters will only be used from the closest
matching font on the system. No fallback will be done to other
fonts on the system that might contain the characters in the text.
Fallback is enabled by default. Most applications should not
disable fallback.</para>
</listitem>
<listitem>
<para><literal>allow_breaks</literal>:
<literal>true</literal> or <literal>false</literal> whether to allow line breaks or not. If
not allowed, the range will be kept in a single run as far
as possible. Breaks are allowed by default.</para>
</listitem>
<listitem>
<para><literal>insert_hyphens</literal>:<literal>
</literal>true<literal> or </literal>false` whether to insert hyphens when breaking
lines in the middle of a word. Hyphens are inserted by default.</para>
</listitem>
<listitem>
<para><literal>show</literal>:
A value determining how invisible characters are treated.
Possible values are <literal>spaces</literal>, <literal>line-breaks</literal>, <literal>ignorables</literal>
or combinations, such as <literal>spaces|line-breaks</literal>.</para>
</listitem>
<listitem>
<para><literal>lang</literal>:
A language code, indicating the text language</para>
</listitem>
<listitem>
<para><literal>letter_spacing</literal>:
Inter-letter spacing in 1024ths of a point.</para>
</listitem>
<listitem>
<para><literal>gravity</literal>:
One of <literal>south</literal>, <literal>east</literal>, <literal>north</literal>, <literal>west</literal>, <literal>auto</literal>.</para>
</listitem>
<listitem>
<para><literal>gravity_hint</literal>:
One of <literal>natural</literal>, <literal>strong</literal>, <literal>line</literal>.</para>
</listitem>
</itemizedlist>
</refsect3>
<refsect3><title>Convenience tags</title><para>The following convenience tags are provided:</para>
<itemizedlist>
<listitem>
<para><literal>&lt;b&gt;</literal>:
Bold</para>
</listitem>
<listitem>
<para><literal>&lt;big&gt;</literal>:
Makes font relatively larger, equivalent to <literal>&lt;span size="larger"&gt;</literal></para>
</listitem>
<listitem>
<para><literal>&lt;i&gt;</literal>:
Italic</para>
</listitem>
<listitem>
<para><literal>&lt;s&gt;</literal>:
Strikethrough</para>
</listitem>
<listitem>
<para><literal>&lt;sub&gt;</literal>:
Subscript</para>
</listitem>
<listitem>
<para><literal>&lt;sup&gt;</literal>:
Superscript</para>
</listitem>
<listitem>
<para><literal>&lt;small&gt;</literal>:
Makes font relatively smaller, equivalent to <literal>&lt;span size="smaller"&gt;</literal></para>
</listitem>
<listitem>
<para><literal>&lt;tt&gt;</literal>:
Monospace</para>
</listitem>
<listitem><para><literal>&lt;u&gt;</literal>:
Underline</para></listitem>
</itemizedlist>
</refsect3>

</refsect1>
<refsect1 id="pango-Markup.functions_details" role="details">
<title role="details.title">Functions</title>
<refsect2 id="pango-parse-markup" role="function">
<title>pango_parse_markup&#160;()</title>
<indexterm zone="pango-parse-markup"><primary>pango_parse_markup</primary></indexterm>
<programlisting language="C"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
pango_parse_markup (<parameter>const <link linkend="char"><type>char</type></link> *markup_text</parameter>,
                    <parameter><link linkend="int"><type>int</type></link> length</parameter>,
                    <parameter><link linkend="gunichar"><type>gunichar</type></link> accel_marker</parameter>,
                    <parameter><link linkend="PangoAttrList"><type>PangoAttrList</type></link> **attr_list</parameter>,
                    <parameter><link linkend="char"><type>char</type></link> **text</parameter>,
                    <parameter><link linkend="gunichar"><type>gunichar</type></link> *accel_char</parameter>,
                    <parameter><link linkend="GError"><type>GError</type></link> **error</parameter>);</programlisting>
<para>Parses marked-up text (see</para>
<link linkend="PangoMarkupFormat">markup format</link>) to create
<para>a plain-text string and an attribute list.</para>
<para>If <parameter>accel_marker</parameter>
 is nonzero, the given character will mark the
character following it as an accelerator. For example, <parameter>accel_marker</parameter>

might be an ampersand or underscore. All characters marked
as an accelerator will receive a <link linkend="PANGO-UNDERLINE-LOW:CAPS"><literal>PANGO_UNDERLINE_LOW</literal></link> attribute,
and the first character so marked will be returned in <parameter>accel_char</parameter>
.
Two <parameter>accel_marker</parameter>
 characters following each other produce a single
literal <parameter>accel_marker</parameter>
 character.</para>
<para>To parse a stream of pango markup incrementally, use <link linkend="pango-markup-parser-new"><function>pango_markup_parser_new()</function></link>.</para>
<para>If any error happens, none of the output arguments are touched except
for <parameter>error</parameter>
.</para>
<refsect3 id="pango-parse-markup.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>markup_text</para></entry>
<entry role="parameter_description"><para>markup to parse (see <link linkend="PangoMarkupFormat">markup format</link>)</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>length</para></entry>
<entry role="parameter_description"><para>length of <parameter>markup_text</parameter>
, or -1 if nul-terminated</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>accel_marker</para></entry>
<entry role="parameter_description"><para>character that precedes an accelerator, or 0 for none</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>attr_list</para></entry>
<entry role="parameter_description"><para>address of return location for a <link linkend="PangoAttrList"><type>PangoAttrList</type></link>, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>allow-none</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>text</para></entry>
<entry role="parameter_description"><para>address of return location for text with tags stripped, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>allow-none</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>accel_char</para></entry>
<entry role="parameter_description"><para>address of return location for accelerator char, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>allow-none</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>error</para></entry>
<entry role="parameter_description"><para>address of return location for errors, or <link linkend="NULL:CAPS"><literal>NULL</literal></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="pango-parse-markup.returns" role="returns">
<title>Returns</title>
<para> <link linkend="FALSE:CAPS"><literal>FALSE</literal></link> if <parameter>error</parameter>
is set, otherwise <link linkend="TRUE:CAPS"><literal>TRUE</literal></link></para>
</refsect3></refsect2>
<refsect2 id="pango-markup-parser-new" role="function" condition="since:1.31.0">
<title>pango_markup_parser_new&#160;()</title>
<indexterm zone="pango-markup-parser-new" role="1.31.0"><primary>pango_markup_parser_new</primary></indexterm>
<programlisting language="C"><link linkend="GMarkupParseContext"><returnvalue>GMarkupParseContext</returnvalue></link>&#160;*
pango_markup_parser_new (<parameter><link linkend="gunichar"><type>gunichar</type></link> accel_marker</parameter>);</programlisting>
<para>Parses marked-up text (see</para>
<link linkend="PangoMarkupFormat">markup format</link>) to create
<para>a plain-text string and an attribute list.</para>
<para>If <parameter>accel_marker</parameter>
 is nonzero, the given character will mark the
character following it as an accelerator. For example, <parameter>accel_marker</parameter>

might be an ampersand or underscore. All characters marked
as an accelerator will receive a <link linkend="PANGO-UNDERLINE-LOW:CAPS"><literal>PANGO_UNDERLINE_LOW</literal></link> attribute,
and the first character so marked will be returned in <parameter>accel_char</parameter>
,
when calling <link linkend="finish"><function>finish()</function></link>. Two <parameter>accel_marker</parameter>
 characters following each
other produce a single literal <parameter>accel_marker</parameter>
 character.</para>
<para>To feed markup to the parser, use <link linkend="g-markup-parse-context-parse"><function>g_markup_parse_context_parse()</function></link>
on the returned <link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link>. When done with feeding markup
to the parser, use <link linkend="pango-markup-parser-finish"><function>pango_markup_parser_finish()</function></link> to get the data out
of it, and then use <link linkend="g-markup-parse-context-free"><function>g_markup_parse_context_free()</function></link> to free it.</para>
<para>This function is designed for applications that read pango markup
from streams. To simply parse a string containing pango markup,
the simpler <link linkend="pango-parse-markup"><function>pango_parse_markup()</function></link> API is recommended instead.</para>
<refsect3 id="pango-markup-parser-new.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>accel_marker</para></entry>
<entry role="parameter_description"><para>character that precedes an accelerator, or 0 for none</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="pango-markup-parser-new.returns" role="returns">
<title>Returns</title>
<para>a <link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link> that should be
destroyed with <link linkend="g-markup-parse-context-free"><function>g_markup_parse_context_free()</function></link>. </para>
<para><emphasis role="annotation">[<acronym>transfer none</acronym>]</emphasis></para>
</refsect3><para role="since">Since: <link linkend="api-index-1.31.0">1.31.0</link></para></refsect2>
<refsect2 id="pango-markup-parser-finish" role="function" condition="since:1.31.0">
<title>pango_markup_parser_finish&#160;()</title>
<indexterm zone="pango-markup-parser-finish" role="1.31.0"><primary>pango_markup_parser_finish</primary></indexterm>
<programlisting language="C"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
pango_markup_parser_finish (<parameter><link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link> *context</parameter>,
                            <parameter><link linkend="PangoAttrList"><type>PangoAttrList</type></link> **attr_list</parameter>,
                            <parameter><link linkend="char"><type>char</type></link> **text</parameter>,
                            <parameter><link linkend="gunichar"><type>gunichar</type></link> *accel_char</parameter>,
                            <parameter><link linkend="GError"><type>GError</type></link> **error</parameter>);</programlisting>
<para>After feeding a pango markup parser some data with <link linkend="g-markup-parse-context-parse"><function>g_markup_parse_context_parse()</function></link>,
use this function to get the list of pango attributes and text out of the
markup. This function will not free <parameter>context</parameter>
, use <link linkend="g-markup-parse-context-free"><function>g_markup_parse_context_free()</function></link>
to do so.</para>
<refsect3 id="pango-markup-parser-finish.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>context</para></entry>
<entry role="parameter_description"><para>A valid parse context that was returned from <link linkend="pango-markup-parser-new"><function>pango_markup_parser_new()</function></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>attr_list</para></entry>
<entry role="parameter_description"><para>address of return location for a <link linkend="PangoAttrList"><type>PangoAttrList</type></link>, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>allow-none</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>text</para></entry>
<entry role="parameter_description"><para>address of return location for text with tags stripped, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>allow-none</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>accel_char</para></entry>
<entry role="parameter_description"><para>address of return location for accelerator char, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>allow-none</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>error</para></entry>
<entry role="parameter_description"><para>address of return location for errors, or <link linkend="NULL:CAPS"><literal>NULL</literal></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="pango-markup-parser-finish.returns" role="returns">
<title>Returns</title>
<para> <link linkend="FALSE:CAPS"><literal>FALSE</literal></link> if <parameter>error</parameter>
is set, otherwise <link linkend="TRUE:CAPS"><literal>TRUE</literal></link></para>
</refsect3><para role="since">Since: <link linkend="api-index-1.31.0">1.31.0</link></para></refsect2>

</refsect1>

</refentry>
