Skip to content

Suggestion #23

@aroberge

Description

@aroberge

Hi,

First, thanks for making this plugin.

I know that you can skip images through a configuration settings but it seems to me to be "brittle" in that it may require a configuration change when new content (including images) is added, or content is moved around.

Glancing at the code, I gather that
https://github.com/todvora/gitbook-plugin-image-captions/blob/master/src/index.js#L145
is the crucial line for determining if an image should be wrapped or not.
Just in case the source changes, the line in question is the last line of

function shouldBeWrapped (img) {
  return img.parent().children().length === 1 &&
         img.parent().text() === '' &&
         (img.attr('title') || img.attr('alt'));
};

I'm thinking that it might be useful to change this last line to something like

(img.attr('title').toLowerCase().startsWith('caption::') || img.attr('alt').toLowerCase().startsWith('caption::'));

and then strip "caption::" from the alt/title text when doing further processing. This way, it would be clear to see by reading the markdown code which images will be processed to add captions, and no information from an outside file (like the config file) would be needed to determine which images should be skipped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions