ruddfawcett / Notepad

[iOS] A fully themeable markdown editor with live syntax highlighting.
http://rudd.fyi/notepad
MIT License
876 stars 105 forks source link

Change Markdown syntax colours #28

Open danielmekis opened 6 years ago

danielmekis commented 6 years ago

Is there any way to use different colours for markdown symbols? Like: **, *, #, etc? (I know, for example the bold has a different colour from the body colour but I would like to set only the markdown syntax's alpha value or it's colour)

ruddfawcett commented 6 years ago

This is currently not supported. It is definitely possible and would include reconfiguring the matching groups on the regex parsing, and thus, in turn, the styling of the attributed strings. Any interest in a pull request to implement this feature?

siburb commented 4 years ago

I've got this working using named capturing groups in the regex, and matching those names to styles using a new property in the style class.

        "handle": {
            "regex": "(?<handleHead>[@@])(?<handleTail>[a-zA-Z0-9_]{1,20})",
            "groups": ["handleHead", "handleTail"]
        },
        "handleHead": {
            "color": "#FF0000"
        },
        "handleTail": {
            "color": "#00FF00"
        },

Named capturing groups are only supported by NSRegularExpression from iOS11 & macOS10.13 (https://developer.apple.com/documentation/foundation/nstextcheckingresult/2915200-range), but we can easily just ignore it in older versions.

This approach seems very flexible, and requires quite minimal changes to the system as a whole. Will polish it up and submit a PR in case you like this direction.

ruddfawcett commented 4 years ago

Hi, @siburb thanks so much. Definitely open to reviewing a PR!