<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # react-markdown 使用備注的React的Markdown組件。 ``` import { Row, Col, Menu, Affix, Anchor } from 'antd'; import ReactMarkdown from 'react-markdown/with-html'; import { isEmpty } from "lodash"; import HeadBlock from './HeadBlock'; import 'github-markdown-css/github-markdown.css' import './index.less'; const { Link } = Anchor; const articles = { '1': '/developer_guide.md', '2': '/user_manual.md' } /** * * @param lists * 這里只做兩級處理 */ export const navsToTree = (lists: any[]) => { if (isEmpty(lists)) return []; // 提取第一個level為最大level 后續比他大的一律為同級 const maxLevel = lists[0].level; const newLists: any[] = []; lists.forEach((item: any) => { // 一級 同級 if (item.level <= maxLevel) { newLists.push(item) } else { // 非同級 if (newLists[newLists.length - 1].children) { newLists[newLists.length - 1].children.push(item) } else { newLists[newLists.length - 1].children = [item] } } }) return newLists; } const NormalTest: React.FC<any> = () => { const [currentArticle, setCurrentArticle] = useState<{ url: string, content: any }>({ url: '', content: '' }); const [treeNavs, setTreeNavs] = useState<any[]>([]) // 初始為開發文檔 useEffect(() => { // console.log(1); changeCurrentArticle(articles['1']) }, []) // 這里是根據文檔修改進行獲取目錄 useEffect(() => { /** * 獲取所有的文章標題 */ // console.log(currentArticle); const markdownNavs = document.querySelectorAll('.article-nav') const navs: any[] = []; markdownNavs.forEach((item: any) => { const level = item.getAttribute('data-level'); const value = item.textContent; const nodeKey = item.id; navs.push({ level, value, nodeKey }) }) transArticleNavs(navs) }, [currentArticle.content]) // 更改當前文檔 const changeCurrentArticle = async (url: string) => { const res = await fetch(url); const content = await res.text(); setCurrentArticle({ ...currentArticle, content, url }) } // 書籍導航點擊 const menuOnClick = (e: any) => { const url = articles[e.key] changeCurrentArticle(url) } // 轉換為文章右側目錄 const transArticleNavs = (navs: any) => { // 轉換為二級導航 const treedevelopDocs = navsToTree(navs); setTreeNavs(treedevelopDocs) } return ( <> <Row className='articles'> <Col flex='200px' className="articles-list"> <Affix offsetTop={24}> <Menu defaultSelectedKeys={['1']} onClick={menuOnClick} theme='light'> <Menu.Item key="1">開發文檔</Menu.Item> <Menu.Item key="2">使用文檔</Menu.Item> </Menu> </Affix> </Col> <Col flex='1' className='articles-content'> <div className='articles-content_wrpper'> <ReactMarkdown className="markdown-body" source={currentArticle.content} escapeHtml={false} renderers={{ heading: HeadBlock }} /> </div> </Col> <Col flex='200px' className="articles-menu"> <Affix offsetTop={20} > <Anchor style={{ width: 160 }}> { treeNavs.map((item: any) => { if (item.children) { return ( <Link href={`###${item.nodeKey}`} title={item.value} key={item.nodeKey}> { item.children.map((childItem: any) => ( <Link href={`###${childItem.nodeKey}`} title={childItem.value} key={childItem.nodeKey} /> )) } </Link> ) } else { return ( <Link href={`###${item.nodeKey}`} title={item.value} key={item.nodeKey} /> ) } }) } </Anchor> </Affix> </Col> </Row> </> ); }; export default NormalTest; ``` ``` import React from 'react'; const HeadBlock = (props) => { const { level, children } = props; const { nodeKey } = children[0].props; return ( <> {React.createElement(`h${level}`, { className: 'article-nav', id: nodeKey, 'data-level': level }, children)} </> ); } export default HeadBlock; ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看