Skip to content

Commit

Permalink
Zone finder based on Markdown Fenced Code blocks; disabled the Exampl…
Browse files Browse the repository at this point in the history
…e Finder

Mark the Markdown fenced-code blocks and the html comment blocks in a
markdown file (.md) as valide zones to find examples.
Disabled the MarkdownFencedCodeFinder example finder, no longer
supported.
  • Loading branch information
eldipa committed Dec 15, 2018
1 parent 46ef5d9 commit c0d6e05
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions byexample/modules/markdown.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import unicode_literals
import re
from byexample.finder import ExampleFinder
from byexample.finder import ExampleFinder, ZoneFinder

stability = 'stable'

class FencedMatchFinder(ExampleFinder):
target = 'markdown-fenced-code'
class FencedMatchFinder: #(ExampleFinder):
#target = 'markdown-fenced-code'
specific = False

def example_regex(self):
Expand Down Expand Up @@ -47,3 +47,28 @@ def get_language_of(self, options, match, where):
def spurious_endings(self):
endings = ExampleFinder.spurious_endings(self)
return endings - {'```', '~~~'}

class MarkdownFencedCodeFinder(ZoneFinder):
target = {'.md'}

def zone_regex(self):
return re.compile(r'''
# Begin with a markdown fenced-code marker or a html comment marker
^[ ]*
(?:
(?P<marker>```(?:``)*(?=[^`])) # fenced-code marker (backticks)
| (?:<!--) # or the html comment marker
)
# then, grab everything until the first end marker
(?P<zone>(?:.*?\n)*?)
# finally, the end marker
^[ ]*
(?(marker) # if we matched a fenced-code maker previously
(?P=marker) # then we must match the same amount of backticks
|(?:-->) # otherwise, we must match the close of the html comment
)
[ ]*$\n?
''', re.MULTILINE | re.VERBOSE)

0 comments on commit c0d6e05

Please sign in to comment.