Macro to put a reference on particular strings to create figure links?

Macro to put a reference on particular strings to create figure links?

81
Advanced UserAdvanced User
81

    Feb 22, 2016#1

    A want to make a macro which will put a link on all expression "fig./figure xyz", the link will be like:
    "<xref ref-type="figure" ref-id="fig0002">fig. 2</xref>"/"<xref ref-type="figure" ref-id="fig0025">Figure 25</xref>"

    The id will be always a four digit number, i.e. the links for figure 1 , 10, 100 will be ref-id="fig0001", ref-id="fig0010" ref-id="fig0100" respectively

    Sample:

    Code: Select all

    If a file with file extension .js is active in UltraEdit, the menu in fig. 5 Scripting contains the menu item figure 12 Run Active Script. If the active *.js file is really an UltraEdit script not designed for running on active file, Figure 113 this command can be used to run the UltraEdit script. But most scripts are designed to run on active file and require therefore a different method for execution.
    After macro sample:

    Code: Select all

    If a file with file extension .js is active in UltraEdit, the menu in <xref ref-type="figure" ref-id="fig0005">fig. 5</xref> Scripting contains the menu item <xref ref-type="figure" ref-id="fig0012">figure 12</xref> Run Active Script. If the active *.js file is really an UltraEdit script not designed for running on active file, <xref ref-type="figure" ref-id="fig0113">Figure 113</xref> this command can be used to run the UltraEdit script. But most scripts are designed to run on active file and require therefore a different method for execution.

    6,681583
    Grand MasterGrand Master
    6,681583

      Feb 22, 2016#2

      This macro was created with UE v13.20a+1 and should therefore work with all newer versions of UE as well.

      Code: Select all

      InsertMode
      ColumnModeOff
      HexOff
      PerlReOn
      Find RegExp "\<(fig\.|figure) (\d)\>(?!</xref>)"
      Replace All "<xref ref-type="figure" ref-id="fig000\2">\1 \2</xref>"
      Find RegExp "\<(fig\.|figure) (\d{2})\>(?!</xref>)"
      Replace All "<xref ref-type="figure" ref-id="fig00\2">\1 \2</xref>"
      Find RegExp "\<(fig\.|figure) (\d{3})\>(?!</xref>)"
      Replace All "<xref ref-type="figure" ref-id="fig0\2">\1 \2</xref>"
      Find RegExp "\<(fig\.|figure) (\d{4})\>(?!</xref>)"
      Replace All "<xref ref-type="figure" ref-id="fig\2">\1 \2</xref>"
      
      The macro reformats first the figure references with 1 digit, next those with 2 digits, then those with 3 digits and last those with 4 digits. Existing figure references with end tag </xref> already present after the figure number are ignored by all 4 Perl regexp replaces because of the negative lookahead verifying if there is not already </xref> after the figure number.
      Best regards from an UC/UE/UES for Windows user from Austria

      81
      Advanced UserAdvanced User
      81

        Feb 23, 2016#3

        Thanks, this macro worked well.