iOS 使用markdown 實現編輯和預覽文本
注意要點:
1.在iOS 可以依賴UIWebview 來實現
2.豐富的UI樣式依賴 html 的樣式, js 調用插入markdown內容呈現出來
3.實現markdown編輯快捷鍵:參考github 編輯內容的快捷鍵即可
?? 實現過程中遇到一個問題,在github上 編輯好的文本,客戶端在線預覽的時候是空白的。。。調試了好久終于找到問題:一樣的文本在pc端可能會生成\r,但是在iOS 客戶端回車鍵只會是\n. 所以markdown文本在注入js前執行的過濾方案中我多加了一條過濾\r 即問題解決了
- (NSString *)getMarkdownContentWithMarkdowString:(NSString *)markdown { markdown = [markdown stringByReplacingOccurrencesOfString:@"\r"withString:@""];//??防止不識別\r markdown = [markdown stringByReplacingOccurrencesOfString:@"\n"withString:@"\\n"]; markdown = [markdown stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]; markdown = [markdown stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"]; return markdown; }
測試復現這種情況 可以使用下面的測試文案:
(1)driving off the spleen and regulating the circulation.\r\n //無法顯示 (2)driving off the spleen and regulating the circulation.\r //無法顯示 (3)driving off the spleen and regulating the circulation.\n //正常 (4)driving off the spleen and regulating the circulation. //正常
markdown 編輯效果如下:

markdown 預覽效果如下:
參考項目:地址 https://github.com/Li-Qun/EditMarkdownDemo
歡迎給小星星???鼓勵哦??????
posted on 2019-03-21 16:25 ACM_Someone like you 閱讀(1553) 評論(0) 收藏 舉報
浙公網安備 33010602011771號