Skip to content

Commit 5b8e8b0

Browse files
committed
Update markdown to html
1 parent 9e117c7 commit 5b8e8b0

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

_search/server/tutorials.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,27 @@ def process_cell(cell):
5050
result = ''
5151

5252
if 'source' in cell:
53-
result += filter_data("".join(cell['source']))
53+
s = "".join(cell['source'])
54+
if 'cell_type' in cell and cell['cell_type'] == 'markdown':
55+
s = markdown_to_html(s)
56+
result += s
5457

5558
# case 1: code cell
5659
if 'outputs' in cell:
5760
for o in cell['outputs']:
5861
if 'text' in o:
59-
result += filter_data("".join(o['text']))
62+
result += "".join(o['text'])
6063
if 'data' in o:
61-
for k,v in o['data'].items():
62-
if k in ('text/html', 'text/plain'):
63-
result += filter_data("".join(v))
64-
64+
if 'text/html' in o['data']:
65+
result += "".join(o['data']['text/html'])
66+
if 'text/plain' in o['data']:
67+
result += f"<pre>{''.join(o['data']['text/plain'])}</pre>"
68+
6569
return result
6670

67-
# takes input of string; filters html and other data
68-
def filter_data(data):
69-
# if len(data) > 5000:
70-
filtered = re.sub('<[^>]*>', '', data)
71-
return filtered # this string will have markup with it
72-
# TODO: remove markup from data
71+
# TODO: convert markdown to html
72+
def markdown_to_html(data):
73+
return data
7374

7475
def load_imagej_tutorials(root):
7576
"""
@@ -99,7 +100,7 @@ def load_imagej_tutorials(root):
99100
doc = parse_notebook(nbfile)
100101
if doc:
101102
nbpath = str(nbfile)[len(str(root)) + 1:]
102-
doc['url'] = f'https://github.com/imagej/tutorials/blob/master/{nbpath}'
103+
doc['id'] = f'https://github.com/imagej/tutorials/blob/master/{nbpath}'
103104
documents.append(doc)
104105
except:
105106
logger.error(f'Failed to parse {Path}:')
@@ -112,7 +113,7 @@ def main(args):
112113
docs = load_imagej_tutorials(args[0])
113114
for doc in docs:
114115
# pprint(doc)
115-
print(doc['url'])
116+
print(doc['id'])
116117

117118
if __name__ == '__main__':
118119
main(['/Users/jackrueth/code/imagej/tutorials'])

0 commit comments

Comments
 (0)