micromarkdown.js icon indicating copy to clipboard operation
micromarkdown.js copied to clipboard

Image title incorrect

Open davidearl opened this issue 8 years ago • 1 comments

At present the alt text for an image is also put into the title, where the spec[1] puts the title as an optional string after the URL.

I think you can fix it as follows: (a) change the links pattern at line 24 to links: /!?\[([^\]<>]+)\]\(([^ \)<>]+)( "([^\(\)\"]+)")?\)/g, (that is, to be enable extraction of the title text between the quotes), and

(b) replace the img element construction at line 190 with str = str.replace(stra[0], '<img src="' + stra[2] + '" alt="' + stra[1] + '"' + (stra[4] ? '" title="' + stra[4] + '" ' : '') + '/>'); recognising that title is optional.

Thanks for this useful library.

[1] https://daringfireball.net/projects/markdown/syntax#img

davidearl avatar Jun 23 '16 10:06 davidearl

Sorry, I had an extra quote, I meant: str = str.replace(stra[0], '<img src="' + stra[2] + '" alt="' + stra[1] + '"' + (stra[4] ? ' title="' + stra[4] + '" ' : '') + '/>');

davidearl avatar Jun 23 '16 10:06 davidearl