494
494
if (strlen(blockType) == 0) {
495
495
return ((ch == '%') && (chNext == '>'));
496
496
} else if ((0 == strcmp(blockType, "inherit")) ||
497
(0 == strcmp(blockType, "namespace")) ||
497
(0 == strcmp(blockType, "namespace")) ||
498
498
(0 == strcmp(blockType, "include")) ||
499
499
(0 == strcmp(blockType, "page"))) {
500
500
return ((ch == '/') && (chNext == '>'));
510
static bool isDjangoBlockEnd(const int ch, const int chNext, const char *blockType) {
511
if (strlen(blockType) == 0) {
513
} else if (0 == strcmp(blockType, "%")) {
514
return ((ch == '%') && (chNext == '}'));
515
} else if (0 == strcmp(blockType, "{")) {
516
return ((ch == '}') && (chNext == '}'));
510
522
static bool isPHPStringState(int state) {
512
524
(state == SCE_HPHP_HSTRING) ||
575
587
styler.StartAt(startPos, static_cast<char>(STYLE_MAX));
576
588
char prevWord[200];
577
589
prevWord[0] = '\0';
580
590
char phpStringDelimiter[200]; // PHP is not limited in length, we are
581
591
phpStringDelimiter[0] = '\0';
582
592
int StateToPrint = initStyle;
583
593
int state = stateForPrintState(StateToPrint);
584
594
char makoBlockType[200];
585
595
makoBlockType[0] = '\0';
596
char djangoBlockType[2];
597
djangoBlockType[0] = '\0';
587
599
// If inside a tag, it may be a script tag, so reread from the start to ensure any language tags are seen
588
600
if (InTagState(state)) {
612
624
// Default client and ASP scripting language is JavaScript
613
625
lineState = eScriptJS << 8;
615
// property asp.default.language
616
// Script in ASP code is initially assumed to be in JavaScript.
627
// property asp.default.language
628
// Script in ASP code is initially assumed to be in JavaScript.
617
629
// To change this to VBScript set asp.default.language to 2. Python is 3.
618
630
lineState |= styler.GetPropertyInt("asp.default.language", eScriptJS) << 4;
630
642
if (inScriptType == eNonHtmlScript && state == SCE_H_COMMENT) {
631
643
scriptLanguage = eScriptComment;
645
script_type beforeLanguage = ScriptOfState(beforePreProc);
634
// property fold.html
635
// Folding is turned on or off for HTML and XML files with this option.
647
// property fold.html
648
// Folding is turned on or off for HTML and XML files with this option.
636
649
// The fold option must also be on for folding to occur.
637
650
const bool foldHTML = styler.GetPropertyInt("fold.html", 0) != 0;
639
652
const bool fold = foldHTML && styler.GetPropertyInt("fold", 0);
641
// property fold.html.preprocessor
642
// Folding is turned on or off for scripts embedded in HTML files with this option.
654
// property fold.html.preprocessor
655
// Folding is turned on or off for scripts embedded in HTML files with this option.
643
656
// The default is on.
644
657
const bool foldHTMLPreprocessor = foldHTML && styler.GetPropertyInt("fold.html.preprocessor", 1);
646
659
const bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
648
// property fold.hypertext.comment
649
// Allow folding for comments in scripts embedded in HTML.
650
// The default is off.
661
// property fold.hypertext.comment
662
// Allow folding for comments in scripts embedded in HTML.
663
// The default is off.
651
664
const bool foldComment = fold && styler.GetPropertyInt("fold.hypertext.comment", 0) != 0;
653
// property fold.hypertext.heredoc
654
// Allow folding for heredocs in scripts embedded in HTML.
655
// The default is off.
666
// property fold.hypertext.heredoc
667
// Allow folding for heredocs in scripts embedded in HTML.
668
// The default is off.
656
669
const bool foldHeredoc = fold && styler.GetPropertyInt("fold.hypertext.heredoc", 0) != 0;
658
// property html.tags.case.sensitive
659
// For XML and HTML, setting this property to 1 will make tags match in a case
660
// sensitive way which is the expected behaviour for XML and XHTML.
671
// property html.tags.case.sensitive
672
// For XML and HTML, setting this property to 1 will make tags match in a case
673
// sensitive way which is the expected behaviour for XML and XHTML.
661
674
const bool caseSensitive = styler.GetPropertyInt("html.tags.case.sensitive", 0) != 0;
663
// property lexer.xml.allow.scripts
664
// Set to 0 to disable scripts in XML.
676
// property lexer.xml.allow.scripts
677
// Set to 0 to disable scripts in XML.
665
678
const bool allowScripts = styler.GetPropertyInt("lexer.xml.allow.scripts", 1) != 0;
667
// property lexer.html.mako
668
// Set to 1 to enable the mako template language.
680
// property lexer.html.mako
681
// Set to 1 to enable the mako template language.
669
682
const bool isMako = styler.GetPropertyInt("lexer.html.mako", 0) != 0;
684
// property lexer.html.django
685
// Set to 1 to enable the django template language.
686
const bool isDjango = styler.GetPropertyInt("lexer.html.django", 0) != 0;
671
688
const CharacterSet setHTMLWord(CharacterSet::setAlphaNum, ".-_:!#", 0x80, true);
672
689
const CharacterSet setTagContinue(CharacterSet::setAlphaNum, ".-_:!#[", 0x80, true);
673
690
const CharacterSet setAttributeContinue(CharacterSet::setAlphaNum, ".-_:!#/", 0x80, true);
888
905
// handle the start Mako template Python code
889
else if (isMako && scriptLanguage == eScriptNone && ((ch == '<' && chNext == '%') ||
906
else if (isMako && scriptLanguage == eScriptNone && ((ch == '<' && chNext == '%') ||
890
907
(lineStartVisibleChars == 1 && ch == '%') ||
891
908
(ch == '$' && chNext == '{') ||
892
909
(ch == '<' && chNext == '/' && chNext2 == '%'))) {
894
911
strcpy(makoBlockType, "%");
896
913
strcpy(makoBlockType, "{");
897
914
else if (chNext == '/')
898
915
GetNextWord(styler, i+3, makoBlockType, sizeof(makoBlockType));
951
// handle the start Django template code
952
else if (isDjango && scriptLanguage != eScriptPython && (ch == '{' && (chNext == '%' || chNext == '{'))) {
954
strcpy(djangoBlockType, "%");
956
strcpy(djangoBlockType, "{");
957
styler.ColourTo(i - 1, StateToPrint);
958
beforePreProc = state;
959
if (inScriptType == eNonHtmlScript)
960
inScriptType = eNonHtmlScriptPreProc;
962
inScriptType = eNonHtmlPreProc;
966
state = SCE_HP_START;
967
beforeLanguage = scriptLanguage;
968
scriptLanguage = eScriptPython;
969
styler.ColourTo(i, SCE_H_ASP);
970
if (foldHTMLPreprocessor && chNext == '%')
973
ch = static_cast<unsigned char>(styler.SafeGetCharAt(i));
934
977
// handle the start of ASP pre-processor = Non-HTML
935
else if (!isMako && !isCommentASPState(state) && (ch == '<') && (chNext == '%') && !isPHPStringState(state)) {
978
else if (!isMako && !isDjango && !isCommentASPState(state) && (ch == '<') && (chNext == '%') && !isPHPStringState(state)) {
936
979
styler.ColourTo(i - 1, StateToPrint);
937
980
beforePreProc = state;
938
981
if (inScriptType == eNonHtmlScript)
1076
// handle the end of Django template code
1077
else if (isDjango &&
1078
((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) &&
1079
(scriptLanguage != eScriptNone) && stateAllowsTermination(state) &&
1080
isDjangoBlockEnd(ch, chNext, djangoBlockType)) {
1081
if (state == SCE_H_ASPAT) {
1082
aspScript = segIsScriptingIndicator(styler,
1083
styler.GetStartSegment(), i - 1, aspScript);
1085
if (state == SCE_HP_WORD) {
1086
classifyWordHTPy(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord, inScriptType);
1088
styler.ColourTo(i - 1, StateToPrint);
1092
styler.ColourTo(i, SCE_H_ASP);
1093
state = beforePreProc;
1094
if (inScriptType == eNonHtmlScriptPreProc)
1095
inScriptType = eNonHtmlScript;
1097
inScriptType = eHtml;
1098
if (foldHTMLPreprocessor) {
1101
scriptLanguage = beforeLanguage;
1033
1105
// handle the end of a pre-processor = Non-HTML
1034
else if ((!isMako && ((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) &&
1106
else if ((!isMako && !isDjango && ((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) &&
1035
1107
(((scriptLanguage != eScriptNone) && stateAllowsTermination(state))) &&
1036
1108
(((ch == '%') || (ch == '?')) && (chNext == '>'))) ||
1037
1109
((scriptLanguage == eScriptSGML) && (ch == '>') && (state != SCE_H_SGML_COMMENT))) {