Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for RTL languages for readme markdown preview. #139644

Merged
merged 2 commits into from Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -111,7 +111,7 @@ export class MarkdownContentProvider {
resourceProvider: WebviewResourceProvider,
): Promise<MarkdownContentProviderOutput> {
const rendered = await this.engine.render(markdownDocument, resourceProvider);
const html = `<div class="markdown-body">${rendered.html}<div class="code-line" data-line="${markdownDocument.lineCount}"></div></div>`;
const html = `<div class="markdown-body" dir="auto">${rendered.html}<div class="code-line" data-line="${markdownDocument.lineCount}"></div></div>`;
return {
html,
containingImages: rendered.containingImages
Expand Down
3 changes: 2 additions & 1 deletion extensions/markdown-language-features/src/markdownEngine.ts
Expand Up @@ -25,6 +25,7 @@ const pluginSourceMap: MarkdownIt.PluginSimple = (md): void => {
if (token.map && token.type !== 'inline') {
token.attrSet('data-line', String(token.map[0]));
token.attrJoin('class', 'code-line');
token.attrJoin('dir', 'auto');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required or is dir inherited by child elements?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjbvz

It is required. Because dir="auto" just looks at the first paragraph and apply direction to all the child element.
Childs just inherit rtl or ltr. Childs doesn't inherit auto and it is not so smart.

I think we can only add dir="auto" to the code-line classes (childs). But for markdown-body class is optional.

}
}
});
Expand Down Expand Up @@ -178,7 +179,7 @@ export class MarkdownEngine {

return engine.parse(text.replace(UNICODE_NEWLINE_REGEX, ''), {});
}

public resetSlugCount(): void {
Copy link
Contributor Author

@SMSadegh19 SMSadegh19 Jan 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we have an empty extra line here.

this._slugCount = new Map<string, number>();
}
Expand Down