def read_tutorial(cat_id, page): tut = read_tutorial_page(cat_id, page) if tut is None: app.logger.info("No tutorial available for %s/%s" % (cat_id, str(page))) return None content = markdown(tut.text, fenced_code=True) # automatically add event handler for highlighting DOM elements tmp = re.findall('<em>(.*?)</em>', str(content)) for t in tmp: if 'hl_' in t: text = t.split(' hl_')[0] idname = t.split(' hl_')[1] content = re.sub( '<em>{} hl_{}</em>'.format(text, idname), '<em onmouseover="highlightElement('{0}', 'id', true)" onmouseout="highlightElement('{0}', 'id', false)">{1}</em>' .format(idname, text), str(content)) elif 'hlc_' in t: text = t.split(' hlc_')[0] classname = t.split(' hlc_')[1] content = re.sub( '<em>{} hlc_{}</em>'.format(text, classname), '<em onmouseover="highlightElement('{0}', 'class', true)" onmouseout="highlightElement('{0}', 'class', false)">{1}</em>' .format(classname, text), str(content)) # automatically add "ask as query" links after code blocks content = re.sub( '</code>(\s)?</pre>', "</code></pre><div class='show_code'><a href='#' class='show_code'>Ask as query</a></div>", str(content)) content = Markup(content) # check whether there is another tutorial in this category nxt = read_tutorial_page(cat_id, int(page) + 1) prev = read_tutorial_page(cat_id, int(page) - 1) out = dict() out['this'] = { 'cat_id': tut.cat_title, 'page': tut.page, 'title': tut.title, 'text': content } if nxt is not None: out['next'] = { 'cat_id': nxt.cat_id, 'page': nxt.page, 'title': nxt.title } if prev is not None: out['prev'] = { 'cat_id': prev.cat_id, 'page': prev.page, 'title': prev.title } return out
def read_tutorial(cat_id, page): tut = read_tutorial_page(cat_id, page) if tut==None: app.logger.info("No tutorial available for %s/%s" % (cat_id, str(page))) return None content = markdown(tut.text, fenced_code=True) # automatically add event handler for highlighting DOM elements tmp = re.findall('<em>(.*?)</em>', str(content)) for t in tmp: if 'hl_' in t: text = t.split(' hl_')[0] idname = t.split(' hl_')[1] content = re.sub('<em>{} hl_{}</em>'.format(text, idname), '<em onmouseover="highlightElement('{0}', 'id', true)" onmouseout="highlightElement('{0}', 'id', false)">{1}</em>'.format(idname, text), str(content)) elif 'hlc_' in t: text = t.split(' hlc_')[0] classname = t.split(' hlc_')[1] content = re.sub('<em>{} hlc_{}</em>'.format(text, classname), '<em onmouseover="highlightElement('{0}', 'class', true)" onmouseout="highlightElement('{0}', 'class', false)">{1}</em>'.format(classname, text), str(content)) # automatically add "ask as query" links after code blocks content = re.sub('</code>(\s)?</pre>', "</code></pre><div class='show_code'><a href='#' class='show_code'>Ask as query</a></div>", str(content)) content = Markup(content) # check whether there is another tutorial in this category nxt = read_tutorial_page(cat_id, int(page)+1) prev = read_tutorial_page(cat_id, int(page)-1) out = {} out['this'] = { 'cat_id': tut.cat_title, 'page': tut.page, 'title': tut.title, 'text': content } if(nxt != None): out['next'] = { 'cat_id': nxt.cat_id, 'page': nxt.page, 'title': nxt.title } if(prev != None): out['prev'] = { 'cat_id': prev.cat_id, 'page': prev.page, 'title': prev.title } return out
def tutorials(cat_id='getting_started', page=1): session['video'] = 0 error = "" # determine hostname/IP we are currently using # (needed for accessing container) host_url = urlparse(request.host_url).hostname container_name = 'tutorials' show_south_pane = False readonly = True authentication = False tut = read_tutorial_page(cat_id, page) content = markdown(tut.text, fenced_code=True) # automatically add event handler for highlighting DOM elements tmp = re.findall('<em>(.*?)</em>', str(content)) for t in tmp: if 'hl_' in t: text = t.split(' hl_')[0] idname = t.split(' hl_')[1] content = re.sub( '<em>{} hl_{}</em>'.format(text, idname), '<em onmouseover="knowrob.highlight_element('{0}', 'id', true)" onmouseout="knowrob.highlight_element('{0}', 'id', false)">{1}</em>' .format(idname, text), str(content)) elif 'hlc_' in t: text = t.split(' hlc_')[0] classname = t.split(' hlc_')[1] content = re.sub( '<em>{} hlc_{}</em>'.format(text, classname), '<em onmouseover="knowrob.highlight_element('{0}', 'class', true)" onmouseout="knowrob.highlight_element('{0}', 'class', false)">{1}</em>' .format(classname, text), str(content)) # automatically add "ask as query" links after code blocks content = re.sub( '</code>(\s)?</pre>', "</code></pre><div class='show_code'><a href='#' class='show_code'>Ask as query</a></div>", str(content)) content = Markup(content) # check whether there is another tutorial in this category nxt = read_tutorial_page(cat_id, int(page) + 1) prev = read_tutorial_page(cat_id, int(page) - 1) return render_template('knowrob_tutorial.html', **locals())
def tutorials(cat_id='getting_started', page=1): session['video'] = 0 #if not ensure_application_started('knowrob/hydro-knowrob-daemon'): # return redirect(url_for('user.logout')) error="" # determine hostname/IP we are currently using # (needed for accessing container) host_url = urlparse(request.host_url).hostname container_name = 'tutorials' show_south_pane = False readonly = True authentication = False tut = read_tutorial_page(cat_id, page) content = markdown(tut.text, fenced_code=True) # automatically add event handler for highlighting DOM elements tmp = re.findall('<em>(.*?)</em>', str(content)) for t in tmp: if 'hl_' in t: text = t.split(' hl_')[0] idname = t.split(' hl_')[1] content = re.sub('<em>{} hl_{}</em>'.format(text, idname), '<em onmouseover="knowrob.highlight_element('{0}', 'id', true)" onmouseout="knowrob.highlight_element('{0}', 'id', false)">{1}</em>'.format(idname, text), str(content)) elif 'hlc_' in t: text = t.split(' hlc_')[0] classname = t.split(' hlc_')[1] content = re.sub('<em>{} hlc_{}</em>'.format(text, classname), '<em onmouseover="knowrob.highlight_element('{0}', 'class', true)" onmouseout="knowrob.highlight_element('{0}', 'class', false)">{1}</em>'.format(classname, text), str(content)) # automatically add "ask as query" links after code blocks content = re.sub('</code>(\s)?</pre>', "</code></pre><div class='show_code'><a href='#' class='show_code'>Ask as query</a></div>", str(content)) content = Markup(content) # check whether there is another tutorial in this category nxt = read_tutorial_page(cat_id, int(page)+1) prev = read_tutorial_page(cat_id, int(page)-1) return render_template('knowrob_tutorial.html', **locals())