Markdownosaur icon indicating copy to clipboard operation
Markdownosaur copied to clipboard

Port to macOS, watchOS and adds support for soft line breaks

Open migueldeicaza opened this issue 1 year ago • 1 comments

These changes make Markdownosaur work on MacOS and iOS

migueldeicaza avatar Mar 13 '23 03:03 migueldeicaza

I implemented your soft break implementation and it works, but isn't up to spec with regards to Markdown line breaks. So if you are rendering content, your render might end up looking different than someone else rendering the same content.

Markdown line breaks should be 2 spaces and then a break -> " \n"

I implemented some code to account for this surrounding your soft line break implementation.

mutating public func visitSoftBreak(_ softBreak: SoftBreak) -> NSAttributedString {
        return NSAttributedString(string: " ")
}
    
mutating public func visitLineBreak(_ lineBreak: LineBreak) -> NSAttributedString {
        let result = NSMutableAttributedString()

        for child in lineBreak.children {
            result.append(visit(child))
        }
        result.append(.singleNewline(withFontSize: baseFontSize))

        return result
 }

Soft line breaks being turned into spaces, since this would cause some new sentences to not have a space in front of them without this soft break inserting one in its place. Hope this helps! Thank you for your useful PR.

ejbills avatar Jul 12 '23 00:07 ejbills