Login  Register

Re: About custom converter for inline_anchor

Posted by mojavelinux on May 13, 2020; 10:52pm
URL: https://discuss.asciidoctor.org/About-custom-converter-for-inline-anchor-tp7992p7993.html

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

https://github.com/asciidoctor/asciidoctor-pdf/blob/master/lib/asciidoctor/pdf/converter.rb#L2373-L2387

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