예제 #1
0
파일: main.py 프로젝트: milkmeat/zbox_wiki
def wp_read(req_path, show_full_path, auto_toc, highlight, pages_path,
            show_quick_links, show_source_button):
    full_path = req_path_to_full_path(req_path)

    if conf.button_mode_path:
        buf = commons.text_path2btns_path("/%s" % req_path)
        button_path = commons.md2html(buf)
    else:
        button_path = None

    if os.path.isfile(full_path):
        work_full_path = os.path.dirname(full_path)
        static_file_prefix = os.path.join("/static/pages", os.path.dirname(req_path))

        content = commons.cat(full_path)
        content = commons.strip_bom(content)

        HOME_PAGE = "home"
        if req_path == HOME_PAGE:
            button_path = None
        else:
            show_quick_links = False

    elif os.path.isdir(full_path):
        work_full_path = full_path
        static_file_prefix = os.path.join("/static/pages", req_path)

        buf1 = get_dot_idx_content_by_full_path(full_path) or ""
        buf2 = get_page_file_list_by_req_path(req_path)

        if buf2:
            buf2 = sequence_to_unorder_list(buf2.split("\n"), show_full_path = show_full_path)
        else:
            buf2 = ""

        content = buf1 + "\n" + "----" + "\n" + buf2

    else:
        if req_path == "home" and (not os.path.exists(full_path)):
            return web.seeother("~all")
        else:
            return web.seeother("/%s?action=edit" % req_path)

    content = zw_macro2md(text = content, show_full_path = show_full_path, pages_path = pages_path)

    content = commons.md2html(text = content,
                              work_full_path = work_full_path,
                              static_file_prefix = static_file_prefix)

    static_files = get_the_same_folders_cssjs_files(req_path)
    if not static_files:
        static_files = get_global_static_files(auto_toc = auto_toc, highlight = highlight) + "\n"

    return tpl_render.canvas(conf = conf,
                           req_path = req_path,
                           button_path = button_path,
                           content = content,
                           static_files = static_files,
                           show_quick_links = show_quick_links,
                           show_source_button = show_source_button)
예제 #2
0
파일: mdutils.py 프로젝트: blakme/zbox_wiki
def get_title_by_file_path_in_md(folder_pages_full_path, file_path_suffix):
    prefix = os.path.join(folder_pages_full_path, file_path_suffix)
    a = prefix + ".md"
    b = prefix + ".markdown"

    if os.path.exists(prefix):
        local_full_path = prefix
    elif os.path.exists(a):
        local_full_path = a
    elif os.path.exists(b):
        local_full_path =  b
    else:
        return None

    buf = commons.shutils.cat(local_full_path)
    if buf:
        buf = commons.strip_bom(buf)

    p = '^#\s*(?P<title>.+?)\s*$'
    p_obj = re.compile(p, re.UNICODE | re.MULTILINE)
    match_obj = p_obj.search(buf)

    if match_obj:
        title = match_obj.group('title')
    else:
        title = None
    return title
예제 #3
0
def get_title_from_md(local_full_path):
    buf = commons.shutils.cat(local_full_path)
    if buf:
        buf = commons.strip_bom(buf)

    p = '^#\s*(?P<title>.+?)\s*$'
    p_obj = re.compile(p, re.UNICODE | re.MULTILINE)
    match_obj = p_obj.search(buf)

    if match_obj:
        title = match_obj.group('title')
    else:
        title = None
    return title
예제 #4
0
파일: main.py 프로젝트: bekacho/zbox_wiki
def get_wiki_page_title_by_req_path(req_path):
    full_path = req_path_to_full_path(req_path)
    buf = commons.cat(full_path)
    if buf:
        buf = commons.strip_bom(buf)

    p = '^#\s*(?P<title>.+?)\s*$'
    p_obj = re.compile(p, re.UNICODE | re.MULTILINE)
    match_obj = p_obj.search(buf)

    if match_obj:
        title = match_obj.group('title')
    elif '/' in req_path:
        title = req_path.split('/')[-1].replace('-', ' ')
    else:
        title = "Untitled"

    return title