About custom converter for inline_anchor

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

About custom converter for inline_anchor

guidog
Hello,  

    I'am new here. Maybe someone can help me.

    I have a process to generate dynamic content (sections, chapters, and so on) using a lot Asciidoctor files. I'm not using inlude macro to combine those files for a different reasons.

The ouput is good but I face different problem with cross reference files.

The process read a lot of files make some regex on the fly, put an [[ID]] at the begining of each content and then combine all the content in one file.

I'm trying to use a custom converter to fix some issues with the xref macro because the files doesn't exists anymore.

module AsciidoctorPdfExtensions
    def convert_inline_anchor node
      case node.type
      when :xref

        # if some conditions holds, rewrite target name
            node.target = <HASH_ID_BASED_ON_TARGET>
        # endif

        super
      else
        super
      end
    end
end

Asciidoctor::Pdf::Converter.prepend AsciidoctorPdfExtensions


It seems that this is not enough and that I have to modify other variables. I found that perhaps the following lines

node.attributes['refid'] = node.target
node.attributes['path'] = nil

solve the problem but I'm not sure.

Is it possible to change the target name at that moment?

Regards
guido
Reply | Threaded
Open this post in threaded view
|

Re: About custom converter for inline_anchor

mojavelinux
Administrator
You can study how the attributes for an xref are used here:


If you manipulate these two attribute values (path and refid), then you can call `super` to allow the normal processing to continue.

Best,

-Dan

On Wed, May 13, 2020 at 4:10 PM guidog [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hello,  

    I'am new here. Maybe someone can help me.

    I have a process to generate dynamic content (sections, chapters, and so on) using a lot Asciidoctor files. I'm not using inlude macro to combine those files for a different reasons.

The ouput is good but I face different problem with cross reference files.

The process read a lot of files make some regex on the fly, put an [[ID]] at the begining of each content and then combine all the content in one file.

I'm trying to use a custom converter to fix some issues with the xref macro because the files doesn't exists anymore.

module AsciidoctorPdfExtensions
    def convert_inline_anchor node
      case node.type
      when :xref

        # if some conditions holds, rewrite target name
            node.target = <HASH_ID_BASED_ON_TARGET>
        # endif

        super
      else
        super
      end
    end
end

Asciidoctor::Pdf::Converter.prepend AsciidoctorPdfExtensions


It seems that this is not enough and that I have to modify other variables. I found that perhaps the following lines

node.attributes['refid'] = node.target
node.attributes['path'] = nil

solve the problem but I'm not sure.

Is it possible to change the target name at that moment?

Regards
guido


If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/About-custom-converter-for-inline-anchor-tp7992.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Reply | Threaded
Open this post in threaded view
|

Re: About custom converter for inline_anchor

guidog
Perfect! I took it from there but I was not sure about it.

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: About custom converter for inline_anchor

mojavelinux
Administrator
👍

On Wed, May 13, 2020 at 4:56 PM guidog [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Perfect! I took it from there but I was not sure about it.

Thanks!


If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/About-custom-converter-for-inline-anchor-tp7992p7994.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux