ali-rantakari / peg-markdown-highlight

C library for Markdown syntax highlighting, using a recursive-descent parser.
Other
181 stars 36 forks source link

Right to left direction attribute for Persian, Hebrew, Arabic, ... #2

Closed morteza closed 10 years ago

morteza commented 10 years ago

NTextView already supports RTL writing direction via:

- (void)setBaseWritingDirection:(NSWritingDirection)writingDirection

CSS supports it via direction: rtl;, and you can simply add another attribute name just like text-align attribute. direction is not exactly alignment, and need separate attribute key.

It's gonna change how we suffer writing right-to-left in markdown, and make markdown promotable in more languages.

Thanks for the great job.

ali-rantakari commented 10 years ago

I'm not quite sure I understand what the feature request here is. Are you referring to the stylesheet parser — that the stylesheets should support a "direction" attribute?

morteza commented 10 years ago

Exactly. Something like this:

editor
foreground: 000000
background: ffffff
caret: 000000
direction: rtl
ali-rantakari commented 10 years ago

Even though the stylesheet parser does not explicitly expose a "direction" attribute, you can still add support for it in the code that uses the parser. For example, you can add something like this into -[HGMarkdownHighlighter applyStylesFromStylesheet:withErrorDelegate:errorSelector:]:

if (cur->type == pmh_attr_type_other && strcmp(cur->name, "direction") == 0)
{
    NSWritingDirection direction = NSWritingDirectionNatural;
    if (strcmp(cur->value->string, "rtl") == 0)
        direction = NSWritingDirectionRightToLeft;
    else if (strcmp(cur->value->string, "ltr") == 0)
        direction = NSWritingDirectionLeftToRight;

    [self.targetTextView
     setBaseWritingDirection:direction
     range:NSMakeRange(0, self.targetTextView.string.length)];
}
morteza commented 10 years ago

Thank you indeed. I'll forward your response to the 'Mou' developer.