Re: [gedit-list] How to modify the formatting options for a single <keyword> in a syntax highliting definition for GEdit?



On Tue, Aug 20, 2019 at 8:13 PM Sergio Spina via gedit-list <gedit-list gnome org> wrote:
Now I want to modify the syntax definition so that the keywords in the "formatting elements" context are formatted in a special way: for example: the statement

    <b>phrase one</b>

in GEdit should appear with the words "phrase one" in bold face while the statement

I think this will do what you want:

    <context id="bold-formatting-element">
      <start>(&lt;)(b)\b</start>
      <include>
        <context sub-pattern="0" where="start" style-ref="xml:tag"/>
        <context sub-pattern="1" where="start" style-ref="xml:element-name"/>
        <context sub-pattern="2" where="start" style-ref="formatting-elements"/>

        <context id="bold-start-tag" style-ref="xml:tag" class="no-spell-check" once-_only_="true">
          <start>\%{def:always-match}</start>
          <end>/?&gt;</end>
          <include>
            <context sub-pattern="0" where="end" style-ref="xml:element-name"/>
            <context ref="xml:entity"/>
            <context ref="xml:character-reference"/>
            <context ref="xml:unallowed-chars"/>
            <context ref="xml:namespace"/>
            <context ref="xml:attribute-name"/>
            <context ref="xml:attribute-value"/>
            <context style-ref="def:error" extend-parent="false">
              <match>\S</match>
            </context>
          </include>
        </context>

        <context id="bold-end-tag" style-ref="xml:tag" class="no-spell-check" end-parent="true">
          <start>(&lt;/)(b)\b</start>
          <end>&gt;</end>
          <include>
            <context sub-pattern="1" where="start" style-ref="xml:element-name"/>
            <context sub-pattern="2" where="start" style-ref="formatting-elements"/>
            <context sub-pattern="0" where="end" style-ref="xml:element-name"/>
            <context ref="xml:entity"/>
            <context ref="xml:character-reference"/>
            <context ref="xml:unallowed-chars"/>
            <context ref="xml:namespace"/>
            <context style-ref="def:error" extend-parent="false">
              <match>\S</match>
            </context>
          </include>
        </context>

        <context id="bold-content" style-ref="bold">
          <start>(?&lt;!/&gt;)(?!&lt;/b\b)</start>
          <include>
            <context end-parent="true">
              <match>(?=&lt;/b\b)</match>
            </context>
            <context ref="lcs"/>
          </include>
        </context>

        <context id="bold-self-closing-tag" end-parent="true">
          <match>(?&lt;=/&gt;)</match>
        </context>

      </include>
    </context>

    <context id="lcs">
      <include>
        <context ref="bold-formatting-element"/>
        <context ref="xml:xml"/>
      </include>
    </context>

You will also need to add a bold style.

Hope that helps,
Jeff



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]