Skip to content
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

List Identation #52

Open
bgoncal opened this issue Sep 16, 2019 · 4 comments
Open

List Identation #52

bgoncal opened this issue Sep 16, 2019 · 4 comments

Comments

@bgoncal
Copy link
Contributor

bgoncal commented Sep 16, 2019

I was trying this library and faced the issue that lists doesn't have the correct indentation, like when the content of a line from a list breaks line, the second line starts below the "●" indicator.

What I would expect is to start below of the first character fo the first line

@keylook
Copy link

keylook commented Nov 13, 2019

@cpvbruno as a temporary solution I've changed formatText code to this in my custom MarkDownList class. Indentation now works as expected. I'm not sure why original implementation avoids using paragraph style in lists, because this is obviously right approach.

class MyMarkdownList: MarkdownList {
  
  override func formatText(_ attributedString: NSMutableAttributedString, range: NSRange, level: Int) {
      var string = (0..<level).reduce("") { (string, _) -> String in
        return "\(string)\(separator)"
      }
      string = "\(string)\(indicator) "
      
      let paragraphStyle = NSMutableParagraphStyle()
      let nonOptions = [NSTextTab.OptionKey: Any]()
      paragraphStyle.tabStops = [
          NSTextTab(textAlignment: .left, location: 20, options: nonOptions)]
      paragraphStyle.defaultTabInterval = 20
      paragraphStyle.headIndent = 10
      paragraphStyle.lineSpacing = 0.5
      paragraphStyle.paragraphSpacing = 12
      
      attributedString.addAttributes(
      [NSAttributedString.Key.paragraphStyle : paragraphStyle],
        range: NSMakeRange(0, attributedString.length))
      
      attributedString.replaceCharacters(in: range, with: string)
      
    }
}
}

@RaoulNL
Copy link

RaoulNL commented Nov 12, 2020

I am facing the same problem as @cpvbruno describes. I'm using v1.6.0 of this repository.

Also... how can I apply the solution @keylook has described?
I've tried the following:

let parser = MarkdownParser(font: font, color: UIColor.black)
parser.addCustomElement(MyMarkdownList())
return parser

What am I missing here?
Any help is greatly appreciated.

@t651330
Copy link

t651330 commented Nov 27, 2020

You must disable the link element when initializing the MarkdownParser , because the same regex is used to match the custom element and the link element.

@RaoulNL
Copy link

RaoulNL commented Nov 27, 2020

@t651330 Could you provide an example?

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

No branches or pull requests

4 participants