From 1c0bc7208acd0f5c35d922eabc70319ba082cc46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Thu, 6 Apr 2023 19:27:37 +0800 Subject: [PATCH] update --- example/component/CodeExpander.qml | 84 +++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/example/component/CodeExpander.qml b/example/component/CodeExpander.qml index c2605d0..f3a6bc9 100644 --- a/example/component/CodeExpander.qml +++ b/example/component/CodeExpander.qml @@ -15,8 +15,9 @@ FluExpander{ id:content width:parent.width readOnly:true - text:code + text:highlightQmlCode(code) focus:false + textFormat: FluMultilineTextBox.RichText KeyNavigation.priority: KeyNavigation.BeforeItem background:Rectangle{ radius: 4 @@ -40,4 +41,85 @@ FluExpander{ } } + function htmlEncode(e){ + var i,s; + for(i in s={ + "&":/&/g,//""//":/"/g,"'":/'/g, + "<":/":/>/g,"
":/\n/g, + " ":/ /g," ":/\t/g + })e=e.replace(s[i],i); + return e; + } + + function highlightQmlCode(code) { + // 定义 QML 关键字列表 + var qmlKeywords = [ + "FluTextButton", + "FluAppBar", + "FluAutoSuggestBox", + "FluBadge", + "FluButton", + "FluCalendarPicker", + "FluCalendarView", + "FluCarousel", + "FluCheckBox", + "FluColorPicker", + "FluColorView", + "FluComboBox", + "FluContentDialog", + "FluContentPage", + "FluControl", + "FluDatePicker", + "FluDivider", + "FluDropDownButton", + "FluExpander", + "FluFilledButton", + "FluFlipView", + "FluFocusRectangle", + "FluIcon", + "FluIconButton", + "FluInfoBar", + "FluItem", + "FluMediaPlayer", + "FluMenu", + "FluMenuItem", + "FluMultilineTextBox", + "FluNavigationView", + "FluObject", + "FluPaneItem", + "FluPaneItemExpander", + "FluPaneItemHeader", + "FluPaneItemSeparator", + "FluPivot", + "FluPivotItem", + "FluProgressBar", + "FluProgressRing", + "FluRadioButton", + "FluRectangle", + "FluScrollablePage", + "FluScrollBar", + "FluShadow", + "FluSlider", + "FluTabView", + "FluText", + "FluTextArea", + "FluTextBox", + "FluTextBoxBackground", + "FluTextBoxMenu", + "FluTextButton", + "FluTextFiled", + "FluTimePicker", + "FluToggleSwitch", + "FluTooltip", + "FluTreeView", + "FluWindow", + "FluWindowResize" + ]; + code = code.replace(/\n/g, "
"); + code = code.replace(/ /g, " "); + return code.replace(RegExp("\\b(" + qmlKeywords.join("|") + ")\\b", "g"), "$1"); + } + + + }