-
Notifications
You must be signed in to change notification settings - Fork 56
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
Provide controls to change text direction and alignment #121
Comments
Please provide a few examples of the text alignment issues you're referring to. |
As a quick/temporary solution, I used below custom javascript and css codes in my nodebb forum to set auto direction and text alignment. Custom Javascript: (function(window) {
//https://github.com/kavirajk/isRTL/blob/master/isRTL.js with minor changes
var reRTL, rtlChars;
rtlChars = [
/* arabic ranges*/
'\u0600-\u06FF',
'\u0750-\u077F',
'\uFB50-\uFDFF',
'\uFE70-\uFEFF',
/* hebrew range*/
'\u05D0-\u05FF'
].join("");
reRTL = new RegExp("[" + rtlChars + "]", "g");
window.isRTL = function(text) {
try{
return (text.replace(/[0-9\s\\\/.,\-+="']/g, '')[0].match(reRTL) || []).length > 0;
}catch(e){}
return false;
};
})(window);
(function(window) {
window.setAutoDir = function() {
$('.content p:not(.auto-dir)').each(function(){var elm = $(this); if(isRTL(elm.text())){elm.addClass('auto-dir auto-dir-rtl')}else{elm.addClass('auto-dir auto-dir-ltr')}})
$('.content ul>li:not(.auto-dir)').each(function(){var elm = $(this); if(isRTL(elm.text())){elm.addClass('auto-dir auto-dir-rtl')}else{elm.addClass('auto-dir auto-dir-ltr')}})
}
})(window);
setAutoDir(); Custom CSS/LESS: .topic .content pre{
direction: ltr;
text-align: left;
}
.auto-dir-rtl{
direction:rtl;
text-align:right;
}
.auto-dir-ltr{
direction:ltr;
text-align:left;
} It works fine for the loaded elements but when the page loads new elements (posts, etc) it will not be applied to them. |
so, @alibghz are you looking to mix if we want to support to mixing within the same post, then we need to wrap some content with html tags, Also, re: alignment, alignment isn't necessarily coupled with the direction, I mean, sure by default |
also, mixed directions won't work if HTML is not allowed in the markdown plugin, as well as the alignment feature, markdown doesn't really support alignment. |
@akhoury, actually, I am looking to mix Considering this forum and topic with default theme, all posts' contents are rendered in By exploring the post content code in developer tools, we figure out it consists of some Now, I think we need to detect text direction based on first strong Unicode character of each paragraph or list item and set the default direction and alignment for those tags, so, the theme's setting does not change the post content direction and reading problem will be solved. Adding controls in the editor to change direction and alignment would be a good option but I think it cannot solve the old posts problem since they need to be edited again. Anyway, it is a nice feature for future posts. |
I think I may have found a way to even have the old posts display correctly as well. @julianlam im documenting findings here In @julianlam 's nodebb-plugin-markdown, where 1stThis will add an attribute parser.use(function (md) {
md.core.ruler.before('linkify', 'autodir', function (state) {
state.tokens.forEach(function (token) {
token.attrJoin('dir', 'auto');
});
});
}); 2nd // Add support for attributes
parser.use(require('markdown-it-attrs')); This will add support for attributes to tokens, so we can then use something like
to align this, we can even add left/center/right buttons for alignment, if we do this, we can even add overrides to the
I tested both approaches, they work, although the second one isn't really markdown, it's just a made up syntax inspired from http://pandoc.org/MANUAL.html#extension-header_attributes and the first one is adding an attribute to each token, I don't know if this not that bad, bad or really bad |
ok so, we don't really need However, adding the We could write our own markdown-plugin to do both, add a |
@akhoury so how would one switch text direction in the middle of a post now? As long as it's easily defined I'm okay with it. Right now I think the post body inherits directionality from the top |
So yea, that first PR just detects the language and auto-set the direction for you - I'm still planning to add a button to select the direction and another button to select the alignment, but we need to decide, either use that markdown-attr plugin or write our plugin, since markdown does not support direction or alignment, it has to be done using Also, there is no easy way to add a dropdown-button to the composer that basically opens-up a select list of other buttons, so, on hover or maybe on click show a list of other buttons, and the other would have the right click handler to perform actions, i was thinking of adding a general handler instead of a just a click handler here nodebb-plugin-composer-default/static/lib/composer/formatting.js Lines 75 to 77 in b6ca5da
Or even make it like a ALIGN-BTN DIRECTION-BTN |
I feel like we're unnecessarily attempting to reinvent the wheel here... how do other forums or authoring softwares handle mixed LTR and RTL? |
well, for start, github doesn't support manually setting the direction, it's not even automatic. مرحبا يا بشر. Discourse doesn't either. Other forums that support bbcode do have a way to do it it's really not a thing i've seen offered in markdown editors, it's more in the basic old wysiwyg html editors, where html is manipulated as needed. |
In a multilingual nodebb forum which users may post in both right-to-left and left-to-right languages or use a ltr/rtl theme by their preferences, having no control on selecting proper text direction and alignment is so displeasing!
It would be nice if you could add some controls in the top-side toolbar so the users can specify the proper direction and/or alignment of texts they are posting.
The text was updated successfully, but these errors were encountered: