From 86cce3627d9cda83d80c0fc7f0f341c0b546d4f6 Mon Sep 17 00:00:00 2001
From: Alex C <dreaming.about.electric.sheep@gmail.com>
Date: Fri, 10 Feb 2023 12:19:30 +0000
Subject: [PATCH 1/3] Add option to choose the TOC location: left or right

---
 README.md             | 10 ++++++++++
 ftplugin/markdown.vim |  6 +++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index a3197253..0e6980d9 100644
--- a/README.md
+++ b/README.md
@@ -149,6 +149,16 @@ Try `:help concealcursor` and `:help conceallevel` for details.
 
         let g:vim_markdown_toc_autofit = 1
 
+### Choose TOC window location
+
+-   `g:vim_markdown_toc_location`
+
+    Choose location of the TOC window: left or right.
+    By default it's `left`
+
+        let g:vim_markdown_toc_location = 'right'
+
+
 ### Text emphasis restriction to single-lines
 
 -   `g:vim_markdown_emphasis_multiline`
diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim
index d6e51c21..10e59859 100644
--- a/ftplugin/markdown.vim
+++ b/ftplugin/markdown.vim
@@ -392,7 +392,11 @@ function! s:Toc(...)
     if l:window_type ==# 'horizontal'
         lopen
     elseif l:window_type ==# 'vertical'
-        vertical lopen
+        if g:vim_markdown_toc_location ==# 'right'
+            vertical botright lopen
+        else
+            vertical topleft lopen
+        endif
         " auto-fit toc window when possible to shrink it
         if (&columns/2) > l:header_max_len && l:vim_markdown_toc_autofit == 1
             " header_max_len + 1 space for first header + 3 spaces for line numbers

From 8d569823e4c20bdfffc6ce1b94a9d6930c9835a4 Mon Sep 17 00:00:00 2001
From: Alex Constantino <dreaming.about.electric.sheep@gmail.com>
Date: Wed, 24 Apr 2024 11:28:31 +0000
Subject: [PATCH 2/3] fix failure when g:vim_markdown_toc_location is not
 defined

---
 ftplugin/markdown.vim | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim
index b2a56a5d..39a895b5 100644
--- a/ftplugin/markdown.vim
+++ b/ftplugin/markdown.vim
@@ -392,7 +392,7 @@ function! s:Toc(...)
     if l:window_type ==# 'horizontal'
         lopen
     elseif l:window_type ==# 'vertical'
-        if g:vim_markdown_toc_location ==# 'right'
+        if exists('g:vim_markdown_toc_location') && g:vim_markdown_toc_location ==# 'right'
             vertical botright lopen
         else
             vertical topleft lopen

From 9df9557051159598fb210ea760549a105649e4f1 Mon Sep 17 00:00:00 2001
From: Alex Constantino <dreaming.about.electric.sheep@gmail.com>
Date: Wed, 26 Feb 2025 18:47:02 +0000
Subject: [PATCH 3/3] fix bug with html syntax (cherrypick from upstream)

---
 after/syntax/html.vim | 4 ++++
 1 file changed, 4 insertions(+)
 create mode 100644 after/syntax/html.vim

diff --git a/after/syntax/html.vim b/after/syntax/html.vim
new file mode 100644
index 00000000..e875bcd2
--- /dev/null
+++ b/after/syntax/html.vim
@@ -0,0 +1,4 @@
+" fix issue with less than sign https://github.com/preservim/vim-markdown/issues/138
+syn clear htmlTag
+syn region htmlTag start=+<[^/]+ end=+>+ fold oneline contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster
+