Added MarkdownImage component (#6774)
* Added MarkdownImage component * Fixed unit tests
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
0f69920342
Коммит
2dea567dcf
@@ -4,29 +4,9 @@
|
||||
import * as TextFormatting from './text_formatting.jsx';
|
||||
import * as SyntaxHighlighting from './syntax_highlighting.jsx';
|
||||
|
||||
import {postListScrollChange} from 'actions/global_actions.jsx';
|
||||
|
||||
import marked from 'marked';
|
||||
import katex from 'katex';
|
||||
|
||||
function markdownImageLoaded(image) {
|
||||
if (image.hasAttribute('height') && image.attributes.height.value !== 'auto') {
|
||||
const maxHeight = parseInt(global.getComputedStyle(image).maxHeight, 10);
|
||||
|
||||
if (image.attributes.height.value > maxHeight) {
|
||||
image.style.height = maxHeight + 'px';
|
||||
image.style.width = ((maxHeight * image.attributes.width.value) / image.attributes.height.value) + 'px';
|
||||
} else {
|
||||
image.style.height = image.attributes.height.value + 'px';
|
||||
}
|
||||
} else {
|
||||
image.style.height = 'auto';
|
||||
}
|
||||
|
||||
postListScrollChange();
|
||||
}
|
||||
global.markdownImageLoaded = markdownImageLoaded;
|
||||
|
||||
class MattermostMarkdownRenderer extends marked.Renderer {
|
||||
constructor(options, formattingOptions = {}) {
|
||||
super(options);
|
||||
@@ -155,7 +135,7 @@ class MattermostMarkdownRenderer extends marked.Renderer {
|
||||
if (dimensions.length > 1) {
|
||||
out += ' height="' + dimensions[1] + '"';
|
||||
}
|
||||
out += ' onload="window.markdownImageLoaded(this)" onerror="window.markdownImageLoaded(this)" class="markdown-inline-img"';
|
||||
out += ' class="markdown-inline-img"';
|
||||
out += this.options.xhtml ? '/>' : '>';
|
||||
return out;
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user