'*******************************************************************************
' EverEdit Syntax File
' Language:    Markdown
' Maintainer:  www.everedit.net  
' History:
'   2012/05/15 First Version
'   2013/03/30 Updated i_mdstrong
'   2013/04/10 Added scope names
'   2013/04/12 Supported code span(```)
'	2013/08/10 Updated title and links with [][]
'	2016/09/9  Improved list/tag match
'*******************************************************************************
Include( ".\const.mac" )

Set mk=CreateParser()

Set i_mditem=mk.CreateItem(COLOR_WORD1, "^#{1,6}.*$", False)
Set i_mdno=mk.CreateItem(COLOR_DEFAULT, "(?<=^\s*)([\*\+\-]|(\d+\.))\s.*$", False)
i_mdno.Capture 1, COLOR_WORD2

Set i_mdistrong=mk.CreateItem(COLOR_HIGHLIGHT3, "(?<!\\)\*\*\*[^\*]+?\*\*\*", False)
Set i_mdistrong2=mk.CreateItem(COLOR_HIGHLIGHT3, "___[\S\s]+?___", False)
Set i_mdstrong=mk.CreateItem(COLOR_HIGHLIGHT2, "(?<!\\)\*\*[^\*]+?\*\*", False)
Set i_mdstrong2=mk.CreateItem(COLOR_HIGHLIGHT2, "__[\S\s]+?__", False)
Set i_mditalic=mk.CreateItem(COLOR_HIGHLIGHT4, "(?<!\\|\*)\*[^\*]+?\*", False)
Set i_mditalic2=mk.CreateItem(COLOR_HIGHLIGHT4, "_[\S\s]+?_", False)
Set i_mdlink=mk.CreateItem(COLOR_DEFAULT, "\[(.+?)\]:(.*)", False)
i_mdlink.Capture 1, COLOR_WORD1
i_mdlink.Capture 2, COLOR_URL

Set i_mdlink2=mk.CreateItem(COLOR_DEFAULT, "\[(.+?)\]\((.*?)\)", False)
i_mdlink2.Capture 1, COLOR_WORD1
i_mdlink2.Capture 2, COLOR_URL

Set i_mdlink3=mk.CreateItem(COLOR_DEFAULT, "\[(.+?)\]\[(.+)\]", False)
i_mdlink3.Capture 1, COLOR_WORD1
i_mdlink3.Capture 2, COLOR_URL

Set r_mdtitle=mk.CreateRegion(COLOR_WORD1, "^===={0,20}", "$", False, True)

Set r_mdline1=mk.CreateRegion(COLOR_HIGHLIGHT2, "\*\x20\*\x20\*", "$", False, True)
Set r_mdline2=mk.CreateRegion(COLOR_HIGHLIGHT2, "-\x20-\x20-", "$", False, True)
Set r_mdline3=mk.CreateRegion(COLOR_HIGHLIGHT2, "---", "$", False, True)
Set r_mdline4=mk.CreateRegion(COLOR_HIGHLIGHT2, "^\*\*\*$", "$", False, True)

Set i_list=mk.CreateItem(COLOR_DEFAULT, "(?<=^\s*)(\*)\s.*$", False)
i_list.Capture 1, COLOR_WORD2

Set r_mdquote=mk.CreateRegion(COLOR_COMMENT2, "^\s*>", "^$", False)
Set r_mdcode=mk.CreateRegion(COLOR_COMMENT1, "(?<=^(\x20{4}|\t)).", "^(?!\x20{4})", False)
Set i_mdcodeline=mk.CreateItem(COLOR_COMMENT1, "`.+?`", False)
Set r_mdcodeblock=mk.CreateRegion(COLOR_COMMENT2, "^```", "^```", False)

'simple tag match
Set i_tag=mk.CreateItem(COLOR_TAG, "<[/!]?(\w+)\s*(.*?)>", False)
i_tag.Capture 2, COLOR_WORD2

Set i_toc=mk.CreateItem(COLOR_HIGHLIGHT7, "^\s*\[toc\]\s*$", False)

r_mdcode.AddItem(i_tag)

'symbols
mk.AddItem( mk.CreateItem(COLOR_HIGHLIGHT1, "(?<!\\)\\[^\\]", False) )

mk.AddItem( i_mditem )
mk.AddItem( i_mdno )
mk.AddItem( i_mdlink )
mk.AddItem( i_mdlink2 )
mk.AddItem( i_mdlink3 )

mk.AddItem( i_mditalic2 )
mk.AddItem( i_mdstrong2 )
mk.AddItem( i_mdistrong2 )
mk.AddItem( i_toc )

mk.AddRegion( r_mdline4 )
mk.AddItem( i_mditalic )
mk.AddItem( i_mdstrong )
mk.AddItem( i_mdistrong )

mk.AddRegion( r_mdline1 )
mk.AddRegion( r_mdline2 )
mk.AddRegion( r_mdline3 )

mk.AddItem( i_list )
mk.AddItem( i_tag )

mk.AddRegion( r_mdquote )
mk.AddRegion( r_mdcode )
mk.AddRegion( r_mdcodeblock )
mk.AddItem( i_mdcodeline )
mk.AddRegion( r_mdtitle )

mk.SetPairs( "<>[](){}""""''" )
mk.FoldingMethod="anytext"
mk.FoldAnyText 0, "^#.*"
