Skip to content

allow mutating line and character rules#96

Open
IlyaPuchkaTW wants to merge 1 commit into
SimonFairbairn:masterfrom
IlyaPuchkaTW:mutable-rules
Open

allow mutating line and character rules#96
IlyaPuchkaTW wants to merge 1 commit into
SimonFairbairn:masterfrom
IlyaPuchkaTW:mutable-rules

Conversation

@IlyaPuchkaTW

Copy link
Copy Markdown

Right now it's not possible to easily implement the subset of markdown that would strip all unsupported markdown tags away. The simplest way to do that seem to allow mutating the styles in characters and lines rules. This way users of the library can create set of rules that will strip away unsupported tags, i.e. like this:

extension SwiftyMarkdown {
   static private let stripLineRules = SwiftyMarkdown.lineRules.map { rule -> LineRule in 
       var noStyle = rule
       noStyle.type = .body
       return noStyle
   }
   
   static private let stripCharacterRules = SwiftyMarkdown.characterRules.map { rule -> CharacterRule in
        var noStyle = rule
        noStyle.styles = rule.styles.mapValues { _ in
            CharacterStyle.none
        }
        return noStyle
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants