• Hi there, really appreciate this plugin so far! It’s doing pretty much everything we need.

    However, we will be using this for publishing articles that will have anchor links to the various headings. Is there a method of doing this in the word document template so that it translates over? (the anchor links will always be the same)

    Absolutely happy to pay for the assistance / development on this.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Michael Williamson

    (@michaelwilliamson)

    Mammoth has some support for bookmarks to link within the same document. Is that something you’ve tried, or is that not what you’re trying to accomplish? If you’ve used that in Word but it’s not been used by Mammoth in the final output, then a minimal example document would be helpful.

    As for paying for development: I don’t normally charge for specific work, but donations are welcome if you feel so inclined.

    Thread Starter keeno1979

    (@keeno1979)

    Hi there Michael, thanks ever so much for replying!

    We’ve attempted the bookmarks but that isn’t what we were after

    Effectively, each upload will have the same H2 headings as other uploads. Next to each of these we require

    <h2>Introduction</h2>

    Absolutely happy to make a donation, just tell me where & how to “donate”

    Plugin Author Michael Williamson

    (@michaelwilliamson)

    I think WordPress might have tried to interpret the HTML in your reply (assuming that you were trying to post some sample HTML) — perhaps try wrapping it in backticks?

    Are you looking to do something like:

    <a id="introduction"></a><h2>Introduction</h2>

    ?

    As for the donation: dropping me an e-mail at [email protected] is probably the easiest way to discuss.

    Plugin Author Michael Williamson

    (@michaelwilliamson)

    Mammoth converts bookmarks to anchors, but it strips out bookmarks that aren’t referenced in the document. One possible solution is to:

    * Change mammoth.js (the underlying JavaScript library) to accept an option to convert all bookmarks to anchors, regardless of whether they’re referenced or not.

    * Add your own custom plugin or theme that configures mammoth.js by setting the MAMMOTH_OPTIONS global, such as MAMMOTH_OPTIONS = {includeAllBookmarks: true}.

    * Add bookmarks as needed into your document.

    Does that sound feasible to you?

    Thread Starter keeno1979

    (@keeno1979)

    Hi there, thank you again for responding and giving the options too!

    So I have created a dummy document with a heading “Introduction” which has the bookmark introduction

    However, when I upload it using Mammoth it does indeed convert it to an anchor link, but it comes out as the following
    <h2><a id="post-3301-Introduction"></a>Introduction</h2>

    I’d prefer it if this were just Introduction

    Plugin Author Michael Williamson

    (@michaelwilliamson)

    The ID prefix is set as an option to mammoth.js, so if you can add a custom plugin or theme, you could set the appropriate option e.g. MAMMOTH_OPTIONS = {idPrefix: ""}. Note that this currently doesn’t work since options can’t be overridden, but that’s an easy change for me to make if this works for you.

    Thread Starter keeno1979

    (@keeno1979)

    That would be superb, many thanks! You have my e-mail

    Plugin Author Michael Williamson

    (@michaelwilliamson)

    The change to the way options work will be in the next version. If you’d like to try it out now you can:

    * open mammoth-editor.js in the theme directory
    * find the convertToHtml function, which should be lines 20-33
    * replace those lines with:

        function convertToHtml(input, options) {
            var fullOptions = {prettyPrint: true};
            for (var key in options) {
                fullOptions[key] = options[key];
            }
            if (typeof MAMMOTH_OPTIONS !== "undefined") {
                var customOptions = typeof MAMMOTH_OPTIONS === "function" ? MAMMOTH_OPTIONS(mammoth) : MAMMOTH_OPTIONS;
    
                for (var key in customOptions) {
                    fullOptions[key] = customOptions[key];
                }
            }
            return mammoth.convertToHtml(input, fullOptions);
        }
    

    After that, you should be able to set the JavaScript global MAMMOTH_OPTIONS to {idPrefix: ""}, which should remove the ID prefixes from the anchors.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Adding Anchor Links to Headings’ is closed to new replies.