mirror of https://github.com/procxx/kepka.git
				
				
				
			Improve triple-backtick replacement.
This commit is contained in:
		
							parent
							
								
									44c6050bf2
								
							
						
					
					
						commit
						b7ab4fd086
					
				| 
						 | 
					@ -2386,7 +2386,7 @@ TextWithTags InputField::getTextWithAppliedMarkdown() const {
 | 
				
			||||||
		if (!tag.closed || tag.adjustedStart < from) {
 | 
							if (!tag.closed || tag.adjustedStart < from) {
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		const auto entityLength = tag.adjustedLength - 2 * tagLength;
 | 
							auto entityLength = tag.adjustedLength - 2 * tagLength;
 | 
				
			||||||
		if (entityLength <= 0) {
 | 
							if (entityLength <= 0) {
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -2407,15 +2407,38 @@ TextWithTags InputField::getTextWithAppliedMarkdown() const {
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		addOriginalTextUpTill(tag.adjustedStart);
 | 
							addOriginalTextUpTill(tag.adjustedStart);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							auto entityStart = tag.adjustedStart + tagLength;
 | 
				
			||||||
 | 
							if (tag.tag == kTagPre) {
 | 
				
			||||||
 | 
								// Remove redundant newlines for pre.
 | 
				
			||||||
 | 
								// If ``` is on a separate line add only one newline.
 | 
				
			||||||
 | 
								if (IsNewline(originalText[entityStart])
 | 
				
			||||||
 | 
									&& (result.text.isEmpty()
 | 
				
			||||||
 | 
										|| IsNewline(result.text[result.text.size() - 1]))) {
 | 
				
			||||||
 | 
									++entityStart;
 | 
				
			||||||
 | 
									--entityLength;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								const auto entityEnd = entityStart + entityLength;
 | 
				
			||||||
 | 
								if (IsNewline(originalText[entityEnd - 1])
 | 
				
			||||||
 | 
									&& (originalText.size() <= entityEnd + tagLength
 | 
				
			||||||
 | 
										|| IsNewline(originalText[entityEnd + tagLength]))) {
 | 
				
			||||||
 | 
									--entityLength;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (entityLength > 0) {
 | 
				
			||||||
 | 
								// Add tag text and entity.
 | 
				
			||||||
			result.tags.push_back(TextWithTags::Tag{
 | 
								result.tags.push_back(TextWithTags::Tag{
 | 
				
			||||||
				int(result.text.size()),
 | 
									int(result.text.size()),
 | 
				
			||||||
				entityLength,
 | 
									entityLength,
 | 
				
			||||||
				tag.tag });
 | 
									tag.tag });
 | 
				
			||||||
			result.text.append(originalText.midRef(
 | 
								result.text.append(originalText.midRef(
 | 
				
			||||||
			tag.adjustedStart + tagLength,
 | 
									entityStart,
 | 
				
			||||||
				entityLength));
 | 
									entityLength));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		from = tag.adjustedStart + tag.adjustedLength;
 | 
							from = tag.adjustedStart + tag.adjustedLength;
 | 
				
			||||||
		removed += 2 * tagLength;
 | 
							removed += (tag.adjustedLength - entityLength);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	addOriginalTagsUpTill(originalText.size());
 | 
						addOriginalTagsUpTill(originalText.size());
 | 
				
			||||||
	addOriginalTextUpTill(originalText.size());
 | 
						addOriginalTextUpTill(originalText.size());
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue