mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-26 02:54:20 +00:00
Working file:// link
This commit is contained in:
parent
323b946e1f
commit
f77856852d
@ -8,30 +8,42 @@ class SithRenderer(Renderer):
|
|||||||
return reverse('core:file_detail', kwargs={'file_id': id}) + suffix
|
return reverse('core:file_detail', kwargs={'file_id': id}) + suffix
|
||||||
|
|
||||||
class SithInlineLexer(InlineLexer):
|
class SithInlineLexer(InlineLexer):
|
||||||
def enable_file_link(self):
|
def _process_link(self, m, link, title=None):
|
||||||
# add file_link rules
|
try:
|
||||||
self.rules.file_link = re.compile(
|
file_link = re.compile(
|
||||||
r'dfile://(\d*)/?(\S*)?' # dfile://4000/download
|
r'^file://(\d*)/?(\S*)?' # dfile://4000/download
|
||||||
)
|
)
|
||||||
# Add file_link parser to default rules
|
match = file_link.search(link)
|
||||||
# you can insert it some place you like
|
id = match.group(1)
|
||||||
# but place matters, maybe 2 is not good
|
suffix = match.group(2) or ""
|
||||||
self.default_rules.insert(0, 'file_link')
|
link = reverse('core:file_detail', kwargs={'file_id': id}) + suffix
|
||||||
|
except: pass
|
||||||
|
return super(SithInlineLexer, self)._process_link(m, link, title)
|
||||||
|
|
||||||
def output_file_link(self, m):
|
# def enable_file_link(self):
|
||||||
id = m.group(1)
|
# # add file_link rules
|
||||||
suffix = m.group(2) or ""
|
# self.rules.file_link = re.compile(
|
||||||
# you can create an custom render
|
# r'dfile://(\d*)/?(\S*)?' # dfile://4000/download
|
||||||
# you can also return the html if you like
|
# )
|
||||||
# return directly html like this:
|
# # Add file_link parser to default rules
|
||||||
# return reverse('core:file_detail', kwargs={'file_id': id}) + suffix
|
# # you can insert it some place you like
|
||||||
return self.renderer.file_link(id, suffix)
|
# # but place matters, maybe 2 is not good
|
||||||
|
# self.default_rules.insert(0, 'file_link')
|
||||||
|
|
||||||
|
# def output_file_link(self, m):
|
||||||
|
# id = m.group(1)
|
||||||
|
# suffix = m.group(2) or ""
|
||||||
|
# # you can create an custom render
|
||||||
|
# # you can also return the html if you like
|
||||||
|
# # return directly html like this:
|
||||||
|
# # return reverse('core:file_detail', kwargs={'file_id': id}) + suffix
|
||||||
|
# return self.renderer.file_link(id, suffix)
|
||||||
|
|
||||||
renderer = SithRenderer()
|
renderer = SithRenderer()
|
||||||
inline = SithInlineLexer(renderer)
|
inline = SithInlineLexer(renderer)
|
||||||
|
|
||||||
# enable the features
|
# enable the features
|
||||||
inline.enable_file_link()
|
# inline.enable_file_link()
|
||||||
markdown = Markdown(renderer, inline=inline)
|
markdown = Markdown(renderer, inline=inline)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user