Skip to content

Commit

Permalink
Merge pull request #265 from SuffolkLITLab/highlight-jinja
Browse files Browse the repository at this point in the history
Add an example word macro to highlight all Jinja2 syntax
  • Loading branch information
nonprofittechy authored Aug 2, 2024
2 parents 88f9d9a + 0367377 commit 92149df
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions docassemble/ALToolbox/data/static/highlight_jinja_word_macro.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
' Add this Macro to your Word document, or your normal.dotm file, so you can use it in the future
' https://support.microsoft.com/en-us/office/create-or-run-a-macro-c6b99036-905c-49a6-818a-dfb98b7c3c9c

Sub JinjaHighlighter()
Dim oRange As Range
Dim oDoc As Document
Set oDoc = ActiveDocument

' Search for text between {{ and }} and highlight yellow
Set oRange = oDoc.Content
With oRange.Find
.ClearFormatting
.Text = "\{\{*\}\}"
.MatchWildcards = True
.Wrap = wdFindStop
Do While .Execute
oRange.Start = oRange.Start + 2
oRange.End = oRange.End - 2
oRange.HighlightColorIndex = wdYellow
oRange.Collapse wdCollapseEnd
Loop
End With

' Search for text between {% and %} and highlight turquoise
Set oRange = oDoc.Content
With oRange.Find
.ClearFormatting
.Text = "\{\%*\%\}"
.MatchWildcards = True
.Wrap = wdFindStop
Do While .Execute
oRange.Start = oRange.Start + 2
oRange.End = oRange.End - 2
oRange.HighlightColorIndex = wdTurquoise
oRange.Collapse wdCollapseEnd
Loop
End With
End Sub

0 comments on commit 92149df

Please sign in to comment.