gitbook-plugin-image-captions icon indicating copy to clipboard operation
gitbook-plugin-image-captions copied to clipboard

Suggestion

Open aroberge opened this issue 8 years ago • 2 comments

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.

aroberge avatar Aug 15 '17 12:08 aroberge

Hi @aroberge, Thank you for your suggestion. My concern here is that it changes the default logic from include all to exclude all. This would bring many problems to all current users.

What about doing it the other way around? Allow some images to be prefixed by, let's say ::no-caption and exclude them from processing? Then you could control that from the source without the need of changing configuration, you would still see which of images will / won't be processed and it wouldn't break all current usages.

Let me know if this usage makes sense for you.

Best regards, Tomas

todvora avatar Aug 18 '17 06:08 todvora

On Fri, Aug 18, 2017 at 3:41 AM, Tomas Dvorak [email protected] wrote:

Hi @aroberge https://github.com/aroberge, Thank you for your suggestion. My concern here is that it changes the default logic from include all to exclude all. This would bring many problems to all current users.

What about doing it the other way around? Allow some images to be prefixed by, let's say ::no-caption and exclude them from processing? Then you could control that from the source without the need of changing configuration, you would still see which of images will / won't be processed and it wouldn't break all current usages.

Yes, this would definitely make more sense given that current users should not be affected.

André

Let me know if this usage makes sense for you.

Best regards, Tomas

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/todvora/gitbook-plugin-image-captions/issues/23#issuecomment-323273006, or mute the thread https://github.com/notifications/unsubscribe-auth/AAmbwiX-WHbVF7_miWUJhoTU9jOtbOqgks5sZTIQgaJpZM4O3gmG .

aroberge avatar Aug 18 '17 09:08 aroberge