Login  Register

About custom converter for inline_anchor

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

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