mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
fix font-family issue in WeChat Public Account editor
It could not recognize " in font-family.
This commit is contained in:
parent
7ac97dbcc4
commit
b45f1d9518
@ -84,7 +84,7 @@ pre {
|
|||||||
}
|
}
|
||||||
|
|
||||||
code {
|
code {
|
||||||
font-family: Consolas, Monaco, Andale Mono, Monospace, Courier New;
|
font-family: Consolas, Monaco, Monospace, Courier;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
color: #98C379;
|
color: #98C379;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ pre {
|
|||||||
}
|
}
|
||||||
|
|
||||||
code {
|
code {
|
||||||
font-family: Consolas, Monaco, Andale Mono, Monospace, Courier New;
|
font-family: Consolas, Monaco, Monospace, Courier;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
color: #8E24AA;
|
color: #8E24AA;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ pre {
|
|||||||
}
|
}
|
||||||
|
|
||||||
code {
|
code {
|
||||||
font-family: Consolas, Monaco, Andale Mono, Monospace, Courier New;
|
font-family: Consolas, Monaco, Monospace, Courier;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
color: #8E24AA;
|
color: #8E24AA;
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,9 @@ styles_to_inline_when_copied=all$border:color:display:font-family:font-size:font
|
|||||||
; p - replace the background color of <pre> with that of its child <code>
|
; p - replace the background color of <pre> with that of its child <code>
|
||||||
; n - replace the \n in <pre> with <br>
|
; n - replace the \n in <pre> with <br>
|
||||||
; g - replace local relative/absolute <img> tag with a warning label
|
; g - replace local relative/absolute <img> tag with a warning label
|
||||||
copy_targets="Without Background"$s:b(mark):c:i:x,OneNote$s:b(mark):c:i:m:a:x,"Microsoft Word"$s:p:b(mark|pre):c(pre):i:m:a:x,"WeChat Public Account"$s:p:b(mark|pre):c(pre):g:m:x:n,"Web Editor"$s:p:b(mark|pre):c(pre):m:x:n,"Raw HTML"$r:x
|
; d - add <span> to <code> which is not inside <pre>
|
||||||
|
; f - replace " with ' in font-family style
|
||||||
|
copy_targets="Without Background"$s:b(mark):c:i:x,OneNote$s:b(mark):c:i:m:a:x,"Microsoft Word"$s:p:b(mark|pre):c(pre):i:m:a:x,"WeChat Public Account"$s:p:b(mark|pre):c(pre):g:m:x:n:f,"Web Editor"$s:p:b(mark|pre):c(pre):m:x:n,"Raw HTML"$r:x
|
||||||
|
|
||||||
[shortcuts]
|
[shortcuts]
|
||||||
; Define shortcuts here, with each item in the form "operation=keysequence".
|
; Define shortcuts here, with each item in the form "operation=keysequence".
|
||||||
|
@ -221,6 +221,14 @@ bool VWebUtils::alterHtmlByTargetAction(const QUrl &p_baseUrl, QString &p_html,
|
|||||||
altered = replaceLocalImgWithWarningLabel(p_html);
|
altered = replaceLocalImgWithWarningLabel(p_html);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'd':
|
||||||
|
altered = addSpanInsideCode(p_html);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'f':
|
||||||
|
altered = replaceQuoteInFontFamily(p_html);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -228,7 +236,10 @@ bool VWebUtils::alterHtmlByTargetAction(const QUrl &p_baseUrl, QString &p_html,
|
|||||||
return altered;
|
return altered;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int skipToTagEnd(const QString &p_html, int p_pos, const QString &p_tag)
|
static int skipToTagEnd(const QString &p_html,
|
||||||
|
int p_pos,
|
||||||
|
const QString &p_tag,
|
||||||
|
int *p_endTagIdx = NULL)
|
||||||
{
|
{
|
||||||
QRegExp beginReg(QString("<%1 ").arg(p_tag));
|
QRegExp beginReg(QString("<%1 ").arg(p_tag));
|
||||||
QRegExp endReg(QString("</%1>").arg(p_tag));
|
QRegExp endReg(QString("</%1>").arg(p_tag));
|
||||||
@ -243,7 +254,13 @@ static int skipToTagEnd(const QString &p_html, int p_pos, const QString &p_tag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (nEnd > -1) {
|
if (nEnd > -1) {
|
||||||
|
if (p_endTagIdx) {
|
||||||
|
*p_endTagIdx = nEnd;
|
||||||
|
}
|
||||||
|
|
||||||
pos = nEnd + endReg.matchedLength();
|
pos = nEnd + endReg.matchedLength();
|
||||||
|
} else if (p_endTagIdx) {
|
||||||
|
*p_endTagIdx = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
@ -675,3 +692,96 @@ bool VWebUtils::replaceLocalImgWithWarningLabel(QString &p_html)
|
|||||||
|
|
||||||
return altered;
|
return altered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VWebUtils::addSpanInsideCode(QString &p_html)
|
||||||
|
{
|
||||||
|
bool altered = false;
|
||||||
|
int pos = 0;
|
||||||
|
|
||||||
|
while (pos < p_html.size()) {
|
||||||
|
int tagIdx = p_html.indexOf(m_tagReg, pos);
|
||||||
|
if (tagIdx == -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString tagName = m_tagReg.cap(1);
|
||||||
|
QString lowerName = tagName.toLower();
|
||||||
|
if (lowerName == "pre") {
|
||||||
|
// Skip <pre>.
|
||||||
|
pos = skipToTagEnd(p_html, tagIdx + m_tagReg.matchedLength(), tagName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lowerName != "code") {
|
||||||
|
pos = tagIdx + m_tagReg.matchedLength();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int idx = tagIdx + m_tagReg.matchedLength() - 1;
|
||||||
|
Q_ASSERT(p_html[idx] == '>');
|
||||||
|
QString span = QString("><span%1>").arg(m_tagReg.cap(2));
|
||||||
|
p_html.replace(idx, 1, span);
|
||||||
|
|
||||||
|
int codeEnd = skipToTagEnd(p_html, idx + span.size(), tagName, &idx);
|
||||||
|
Q_ASSERT(idx > -1);
|
||||||
|
Q_ASSERT(codeEnd - idx == 7);
|
||||||
|
Q_ASSERT(p_html[idx] == '<');
|
||||||
|
p_html.replace(idx, 1, "</span><");
|
||||||
|
|
||||||
|
pos = codeEnd;
|
||||||
|
|
||||||
|
altered = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return altered;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @p_html is the style string.
|
||||||
|
static bool replaceQuoteInFontFamilyInStyleString(QString &p_html)
|
||||||
|
{
|
||||||
|
QRegExp reg("font-family:((")|[^;])+;");
|
||||||
|
int idx = p_html.indexOf(reg);
|
||||||
|
if (idx == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString quote(""");
|
||||||
|
QString family = reg.cap(0);
|
||||||
|
if (family.indexOf(quote) == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString newFamily = family.replace(quote, "'");
|
||||||
|
p_html.replace(idx, reg.matchedLength(), newFamily);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VWebUtils::replaceQuoteInFontFamily(QString &p_html)
|
||||||
|
{
|
||||||
|
bool altered = false;
|
||||||
|
int pos = 0;
|
||||||
|
|
||||||
|
while (pos < p_html.size()) {
|
||||||
|
int idx = p_html.indexOf(m_styleTagReg, pos);
|
||||||
|
if (idx == -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString styleStr = m_styleTagReg.cap(3);
|
||||||
|
if (replaceQuoteInFontFamilyInStyleString(styleStr)) {
|
||||||
|
QString newTag = QString("<%1%2style=\"%3\"%4>").arg(m_styleTagReg.cap(1))
|
||||||
|
.arg(m_styleTagReg.cap(2))
|
||||||
|
.arg(styleStr)
|
||||||
|
.arg(m_styleTagReg.cap(4));
|
||||||
|
p_html.replace(idx, m_styleTagReg.matchedLength(), newTag);
|
||||||
|
|
||||||
|
pos = idx + newTag.size();
|
||||||
|
|
||||||
|
altered = true;
|
||||||
|
} else {
|
||||||
|
pos = idx + m_styleTagReg.matchedLength();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return altered;
|
||||||
|
}
|
||||||
|
@ -97,6 +97,12 @@ private:
|
|||||||
// Replace local absolute/relative <img> tag with a warning label.
|
// Replace local absolute/relative <img> tag with a warning label.
|
||||||
bool replaceLocalImgWithWarningLabel(QString &p_html);
|
bool replaceLocalImgWithWarningLabel(QString &p_html);
|
||||||
|
|
||||||
|
// Add <span> inside <code> not in <pre>.
|
||||||
|
bool addSpanInsideCode(QString &p_html);
|
||||||
|
|
||||||
|
// Replace " in font-family with '.
|
||||||
|
bool replaceQuoteInFontFamily(QString &p_html);
|
||||||
|
|
||||||
QVector<CopyTarget> m_copyTargets;
|
QVector<CopyTarget> m_copyTargets;
|
||||||
|
|
||||||
// Custom styles to remove when copied.
|
// Custom styles to remove when copied.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user