{ // 获取包含Hugging Face文本的span元素 const spans = link.querySelectorAll('span.whitespace-nowrap, span.hidden.whitespace-nowrap'); spans.forEach(span => { if (span.textContent && span.textContent.trim().match(/Hugging\s*Face/i)) { span.textContent = 'AI快站'; } }); }); // 替换logo图片的alt属性 document.querySelectorAll('img[alt*="Hugging"], img[alt*="Face"]').forEach(img => { if (img.alt.match(/Hugging\s*Face/i)) { img.alt = 'AI快站 logo'; } }); } // 替换导航栏中的链接 function replaceNavigationLinks() { // 已替换标记,防止重复运行 if (window._navLinksReplaced) { return; } // 已经替换过的链接集合,防止重复替换 const replacedLinks = new Set(); // 只在导航栏区域查找和替换链接 const headerArea = document.querySelector('header') || document.querySelector('nav'); if (!headerArea) { return; } // 在导航区域内查找链接 const navLinks = headerArea.querySelectorAll('a'); navLinks.forEach(link => { // 如果已经替换过,跳过 if (replacedLinks.has(link)) return; const linkText = link.textContent.trim(); const linkHref = link.getAttribute('href') || ''; // 替换Spaces链接 - 仅替换一次 if ( (linkHref.includes('/spaces') || linkHref === '/spaces' || linkText === 'Spaces' || linkText.match(/^s*Spacess*$/i)) && linkText !== 'OCR模型免费转Markdown' && linkText !== 'OCR模型免费转Markdown' ) { link.textContent = 'OCR模型免费转Markdown'; link.href = 'https://fast360.xyz'; link.setAttribute('target', '_blank'); link.setAttribute('rel', 'noopener noreferrer'); replacedLinks.add(link); } // 删除Posts链接 else if ( (linkHref.includes('/posts') || linkHref === '/posts' || linkText === 'Posts' || linkText.match(/^s*Postss*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } // 替换Docs链接 - 仅替换一次 else if ( (linkHref.includes('/docs') || linkHref === '/docs' || linkText === 'Docs' || linkText.match(/^s*Docss*$/i)) && linkText !== '模型下载攻略' ) { link.textContent = '模型下载攻略'; link.href = '/'; replacedLinks.add(link); } // 删除Enterprise链接 else if ( (linkHref.includes('/enterprise') || linkHref === '/enterprise' || linkText === 'Enterprise' || linkText.match(/^s*Enterprises*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } }); // 查找可能嵌套的Spaces和Posts文本 const textNodes = []; function findTextNodes(element) { if (element.nodeType === Node.TEXT_NODE) { const text = element.textContent.trim(); if (text === 'Spaces' || text === 'Posts' || text === 'Enterprise') { textNodes.push(element); } } else { for (const child of element.childNodes) { findTextNodes(child); } } } // 只在导航区域内查找文本节点 findTextNodes(headerArea); // 替换找到的文本节点 textNodes.forEach(node => { const text = node.textContent.trim(); if (text === 'Spaces') { node.textContent = node.textContent.replace(/Spaces/g, 'OCR模型免费转Markdown'); } else if (text === 'Posts') { // 删除Posts文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } else if (text === 'Enterprise') { // 删除Enterprise文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } }); // 标记已替换完成 window._navLinksReplaced = true; } // 替换代码区域中的域名 function replaceCodeDomains() { // 特别处理span.hljs-string和span.njs-string元素 document.querySelectorAll('span.hljs-string, span.njs-string, span[class*="hljs-string"], span[class*="njs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换hljs-string类的span中的域名(移除多余的转义符号) document.querySelectorAll('span.hljs-string, span[class*="hljs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换pre和code标签中包含git clone命令的域名 document.querySelectorAll('pre, code').forEach(element => { if (element.textContent && element.textContent.includes('git clone')) { const text = element.innerHTML; if (text.includes('huggingface.co')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 处理特定的命令行示例 document.querySelectorAll('pre, code').forEach(element => { const text = element.innerHTML; if (text.includes('huggingface.co')) { // 针对git clone命令的专门处理 if (text.includes('git clone') || text.includes('GIT_LFS_SKIP_SMUDGE=1')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 特别处理模型下载页面上的代码片段 document.querySelectorAll('.flex.border-t, .svelte_hydrator, .inline-block').forEach(container => { const content = container.innerHTML; if (content && content.includes('huggingface.co')) { container.innerHTML = content.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 特别处理模型仓库克隆对话框中的代码片段 try { // 查找包含"Clone this model repository"标题的对话框 const cloneDialog = document.querySelector('.svelte_hydration_boundary, [data-target="MainHeader"]'); if (cloneDialog) { // 查找对话框中所有的代码片段和命令示例 const codeElements = cloneDialog.querySelectorAll('pre, code, span'); codeElements.forEach(element => { if (element.textContent && element.textContent.includes('huggingface.co')) { if (element.innerHTML.includes('huggingface.co')) { element.innerHTML = element.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { element.textContent = element.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); } // 更精确地定位克隆命令中的域名 document.querySelectorAll('[data-target]').forEach(container => { const codeBlocks = container.querySelectorAll('pre, code, span.hljs-string'); codeBlocks.forEach(block => { if (block.textContent && block.textContent.includes('huggingface.co')) { if (block.innerHTML.includes('huggingface.co')) { block.innerHTML = block.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { block.textContent = block.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); }); } catch (e) { // 错误处理但不打印日志 } } // 当DOM加载完成后执行替换 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); }); } else { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); } // 增加一个MutationObserver来处理可能的动态元素加载 const observer = new MutationObserver(mutations => { // 检查是否导航区域有变化 const hasNavChanges = mutations.some(mutation => { // 检查是否存在header或nav元素变化 return Array.from(mutation.addedNodes).some(node => { if (node.nodeType === Node.ELEMENT_NODE) { // 检查是否是导航元素或其子元素 if (node.tagName === 'HEADER' || node.tagName === 'NAV' || node.querySelector('header, nav')) { return true; } // 检查是否在导航元素内部 let parent = node.parentElement; while (parent) { if (parent.tagName === 'HEADER' || parent.tagName === 'NAV') { return true; } parent = parent.parentElement; } } return false; }); }); // 只在导航区域有变化时执行替换 if (hasNavChanges) { // 重置替换状态,允许再次替换 window._navLinksReplaced = false; replaceHeaderBranding(); replaceNavigationLinks(); } }); // 开始观察document.body的变化,包括子节点 if (document.body) { observer.observe(document.body, { childList: true, subtree: true }); } else { document.addEventListener('DOMContentLoaded', () => { observer.observe(document.body, { childList: true, subtree: true }); }); } })(); ',\n 'html.parser')\n soup_str = html.SoupString(soup)\n assert isinstance(soup_str, str)\n assert isinstance(soup_str, html.SoupString)\n assert soup_str == '

foo

'\n assert soup_str.soup is soup\n\n\ndef test_listwriter():\n \"\"\"\n Test to make sure the class ListWriter behaves properly.\n \"\"\"\n\n lst = []\n writer = html.ListWriter(lst)\n\n for i in range(5):\n writer.write(i)\n for ch in 'abcde':\n writer.write(ch)\n\n assert lst == [0, 1, 2, 3, 4, 'a', 'b', 'c', 'd', 'e']\n\n\n@pytest.mark.skipif('not HAS_BS4')\ndef test_identify_table():\n \"\"\"\n Test to make sure that identify_table() returns whether the\n given BeautifulSoup tag is the correct table to process.\n \"\"\"\n\n # Should return False on non- tags and None\n soup = BeautifulSoup('', 'html.parser')\n assert html.identify_table(soup, {}, 0) is False\n assert html.identify_table(None, {}, 0) is False\n\n soup = BeautifulSoup('
'\n '
A
B
', 'html.parser').table\n assert html.identify_table(soup, {}, 2) is False\n assert html.identify_table(soup, {}, 1) is True # Default index of 1\n\n # Same tests, but with explicit parameter\n assert html.identify_table(soup, {'table_id': 2}, 1) is False\n assert html.identify_table(soup, {'table_id': 1}, 1) is True\n\n # Test identification by string ID\n assert html.identify_table(soup, {'table_id': 'bar'}, 1) is False\n assert html.identify_table(soup, {'table_id': 'foo'}, 1) is True\n\n\n@pytest.mark.skipif('not HAS_BS4')\ndef test_missing_data():\n \"\"\"\n Test reading a table with missing data\n \"\"\"\n # First with default where blank => '0'\n table_in = ['',\n '',\n '',\n '',\n '
A
1
']\n dat = Table.read(table_in, format='ascii.html')\n assert dat.masked is False\n assert np.all(dat['A'].mask == [True, False])\n assert dat['A'].dtype.kind == 'i'\n\n # Now with a specific value '...' => missing\n table_in = ['',\n '',\n '',\n '',\n '
A
...
1
']\n dat = Table.read(table_in, format='ascii.html', fill_values=[('...', '0')])\n assert dat.masked is False\n assert np.all(dat['A'].mask == [True, False])\n assert dat['A'].dtype.kind == 'i'\n\n\n@pytest.mark.skipif('not HAS_BS4')\ndef test_rename_cols():\n \"\"\"\n Test reading a table and renaming cols\n \"\"\"\n table_in = ['',\n '',\n '',\n '
A B
12
']\n\n # Swap column names\n dat = Table.read(table_in, format='ascii.html', names=['B', 'A'])\n assert dat.colnames == ['B', 'A']\n assert len(dat) == 1\n\n # Swap column names and only include A (the renamed version)\n dat = Table.read(table_in, format='ascii.html', names=['B', 'A'], include_names=['A'])\n assert dat.colnames == ['A']\n assert len(dat) == 1\n assert np.all(dat['A'] == 2)\n\n\n@pytest.mark.skipif('not HAS_BS4')\ndef test_no_names():\n \"\"\"\n Test reading a table with no column header\n \"\"\"\n table_in = ['',\n '',\n '',\n '
1
2
']\n dat = Table.read(table_in, format='ascii.html')\n assert dat.colnames == ['col1']\n assert len(dat) == 2\n\n dat = Table.read(table_in, format='ascii.html', names=['a'])\n assert dat.colnames == ['a']\n assert len(dat) == 2\n\n\n@pytest.mark.skipif('not HAS_BS4')\ndef test_identify_table_fail():\n \"\"\"\n Raise an exception with an informative error message if table_id\n is not found.\n \"\"\"\n table_in = ['',\n '
A
B
']\n\n with pytest.raises(core.InconsistentTableError) as err:\n Table.read(table_in, format='ascii.html', htmldict={'table_id': 'bad_id'},\n guess=False)\n assert err.match(\"ERROR: HTML table id 'bad_id' not found$\")\n\n with pytest.raises(core.InconsistentTableError) as err:\n Table.read(table_in, format='ascii.html', htmldict={'table_id': 3},\n guess=False)\n assert err.match(\"ERROR: HTML table number 3 not found$\")\n\n\n@pytest.mark.skipif('not HAS_BS4')\ndef test_backend_parsers():\n \"\"\"\n Make sure the user can specify which back-end parser to use\n and that an error is raised if the parser is invalid.\n \"\"\"\n for parser in ('lxml', 'xml', 'html.parser', 'html5lib'):\n try:\n Table.read('data/html2.html', format='ascii.html',\n htmldict={'parser': parser}, guess=False)\n except FeatureNotFound:\n if parser == 'html.parser':\n raise\n # otherwise ignore if the dependency isn't present\n\n # reading should fail if the parser is invalid\n with pytest.raises(FeatureNotFound):\n Table.read('data/html2.html', format='ascii.html',\n htmldict={'parser': 'foo'}, guess=False)\n\n\n@pytest.mark.skipif('HAS_BS4')\ndef test_htmlinputter_no_bs4():\n \"\"\"\n This should return an OptionalTableImportError if BeautifulSoup\n is not installed.\n \"\"\"\n\n inputter = html.HTMLInputter()\n with pytest.raises(core.OptionalTableImportError):\n inputter.process_lines([])\n\n\n@pytest.mark.skipif('not HAS_BS4')\ndef test_htmlinputter():\n \"\"\"\n Test to ensure that HTMLInputter correctly converts input\n into a list of SoupStrings representing table elements.\n \"\"\"\n\n f = 'data/html.html'\n with open(f) as fd:\n table = fd.read()\n\n inputter = html.HTMLInputter()\n inputter.html = {}\n\n # In absence of table_id, defaults to the first table\n expected = ['Column 1Column 2Column 3',\n '1a1.05',\n '2b2.75',\n '3c-1.25']\n assert [str(x) for x in inputter.get_lines(table)] == expected\n\n # Should raise an InconsistentTableError if the table is not found\n inputter.html = {'table_id': 4}\n with pytest.raises(core.InconsistentTableError):\n inputter.get_lines(table)\n\n # Identification by string ID\n inputter.html['table_id'] = 'second'\n expected = ['Column AColumn BColumn C',\n '4d10.5',\n '5e27.5',\n '6f-12.5']\n assert [str(x) for x in inputter.get_lines(table)] == expected\n\n # Identification by integer index\n inputter.html['table_id'] = 3\n expected = ['C1C2C3',\n '7g105.0',\n '8h275.0',\n '9i-125.0']\n assert [str(x) for x in inputter.get_lines(table)] == expected\n\n\n@pytest.mark.skipif('not HAS_BS4')\ndef test_htmlsplitter():\n \"\"\"\n Test to make sure that HTMLSplitter correctly inputs lines\n of type SoupString to return a generator that gives all\n header and data elements.\n \"\"\"\n\n splitter = html.HTMLSplitter()\n\n lines = [html.SoupString(BeautifulSoup('
Col 1Col 2
',\n 'html.parser').tr),\n html.SoupString(BeautifulSoup('
Data 1Data 2
',\n 'html.parser').tr)]\n expected_data = [['Col 1', 'Col 2'], ['Data 1', 'Data 2']]\n assert list(splitter(lines)) == expected_data\n\n # Make sure the presence of a non-SoupString triggers a TypeError\n lines.append('Data 3Data 4')\n with pytest.raises(TypeError):\n list(splitter(lines))\n\n # Make sure that passing an empty list triggers an error\n with pytest.raises(core.InconsistentTableError):\n list(splitter([]))\n\n\n@pytest.mark.skipif('not HAS_BS4')\ndef test_htmlheader_start():\n \"\"\"\n Test to ensure that the start_line method of HTMLHeader\n returns the first line of header data. Uses t/html.html\n for sample input.\n \"\"\"\n\n f = 'data/html.html'\n with open(f) as fd:\n table = fd.read()\n\n inputter = html.HTMLInputter()\n inputter.html = {}\n header = html.HTMLHeader()\n\n lines = inputter.get_lines(table)\n assert str(lines[header.start_line(lines)]) == \\\n 'Column 1Column 2Column 3'\n inputter.html['table_id'] = 'second'\n lines = inputter.get_lines(table)\n assert str(lines[header.start_line(lines)]) == \\\n 'Column AColumn BColumn C'\n inputter.html['table_id'] = 3\n lines = inputter.get_lines(table)\n assert str(lines[header.start_line(lines)]) == \\\n 'C1C2C3'\n\n # start_line should return None if no valid header is found\n lines = [html.SoupString(BeautifulSoup('
Data
',\n 'html.parser').tr),\n html.SoupString(BeautifulSoup('

Text

', 'html.parser').p)]\n assert header.start_line(lines) is None\n\n # Should raise an error if a non-SoupString is present\n lines.append('Header')\n with pytest.raises(TypeError):\n header.start_line(lines)\n\n\n@pytest.mark.skipif('not HAS_BS4')\ndef test_htmldata():\n \"\"\"\n Test to ensure that the start_line and end_lines methods\n of HTMLData returns the first line of table data. Uses\n t/html.html for sample input.\n \"\"\"\n\n f = 'data/html.html'\n with open(f) as fd:\n table = fd.read()\n\n inputter = html.HTMLInputter()\n inputter.html = {}\n data = html.HTMLData()\n\n lines = inputter.get_lines(table)\n assert str(lines[data.start_line(lines)]) == \\\n '1a1.05'\n # end_line returns the index of the last data element + 1\n assert str(lines[data.end_line(lines) - 1]) == \\\n '3c-1.25'\n\n inputter.html['table_id'] = 'second'\n lines = inputter.get_lines(table)\n assert str(lines[data.start_line(lines)]) == \\\n '4d10.5'\n assert str(lines[data.end_line(lines) - 1]) == \\\n '6f-12.5'\n\n inputter.html['table_id'] = 3\n lines = inputter.get_lines(table)\n assert str(lines[data.start_line(lines)]) == \\\n '7g105.0'\n assert str(lines[data.end_line(lines) - 1]) == \\\n '9i-125.0'\n\n # start_line should raise an error if no table data exists\n lines = [html.SoupString(BeautifulSoup('
', 'html.parser').div),\n html.SoupString(BeautifulSoup('

Text

', 'html.parser').p)]\n with pytest.raises(core.InconsistentTableError):\n data.start_line(lines)\n\n # end_line should return None if no table data exists\n assert data.end_line(lines) is None\n\n # Should raise an error if a non-SoupString is present\n lines.append('Data')\n with pytest.raises(TypeError):\n data.start_line(lines)\n with pytest.raises(TypeError):\n data.end_line(lines)\n\n\ndef test_multicolumn_write():\n \"\"\"\n Test to make sure that the HTML writer writes multidimensional\n columns (those with iterable elements) using the colspan\n attribute of .\n \"\"\"\n\n col1 = [1, 2, 3]\n col2 = [(1.0, 1.0), (2.0, 2.0), (3.0, 3.0)]\n col3 = [('a', 'a', 'a'), ('b', 'b', 'b'), ('c', 'c', 'c')]\n table = Table([col1, col2, col3], names=('C1', 'C2', 'C3'))\n expected = \"\"\"\\\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
C1C2C3
11.01.0aaa
22.02.0bbb
33.03.0ccc
\n \n\n \"\"\"\n out = html.HTML().write(table)[0].strip()\n assert out == expected.strip()\n\n\n@pytest.mark.skipif('not HAS_BLEACH')\ndef test_multicolumn_write_escape():\n \"\"\"\n Test to make sure that the HTML writer writes multidimensional\n columns (those with iterable elements) using the colspan\n attribute of .\n \"\"\"\n\n col1 = [1, 2, 3]\n col2 = [(1.0, 1.0), (2.0, 2.0), (3.0, 3.0)]\n col3 = [('', '', 'a'), ('', 'b', 'b'), ('c', 'c', 'c')]\n table = Table([col1, col2, col3], names=('C1', 'C2', 'C3'))\n expected = \"\"\"\\\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
C1C2C3
11.01.0a
22.02.0bb
33.03.0ccc
\n \n\n \"\"\"\n out = html.HTML(htmldict={'raw_html_cols': 'C3'}).write(table)[0].strip()\n assert out == expected.strip()\n\n\ndef test_write_no_multicols():\n \"\"\"\n Test to make sure that the HTML writer will not use\n multi-dimensional columns if the multicol parameter\n is False.\n \"\"\"\n\n col1 = [1, 2, 3]\n col2 = [(1.0, 1.0), (2.0, 2.0), (3.0, 3.0)]\n col3 = [('a', 'a', 'a'), ('b', 'b', 'b'), ('c', 'c', 'c')]\n table = Table([col1, col2, col3], names=('C1', 'C2', 'C3'))\n expected = \"\"\"\\\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
C1C2C3
11.0 .. 1.0a .. a
22.0 .. 2.0b .. b
33.0 .. 3.0c .. c
\n \n\n \"\"\"\n assert html.HTML({'multicol': False}).write(table)[0].strip() == \\\n expected.strip()\n\n\n@pytest.mark.skipif('not HAS_BS4')\ndef test_multicolumn_read():\n \"\"\"\n Test to make sure that the HTML reader inputs multidimensional\n columns (those with iterable elements) using the colspan\n attribute of .\n\n Ensure that any string element within a multidimensional column\n casts all elements to string prior to type conversion operations.\n \"\"\"\n\n table = Table.read('data/html2.html', format='ascii.html')\n str_type = np.dtype((str, 21))\n expected = Table(np.array([(['1', '2.5000000000000000001'], 3),\n (['1a', '1'], 3.5)],\n dtype=[('A', str_type, (2,)), ('B', 'x'], ['y']], names=['a', 'b'])\n\n # One column contains raw HTML (string input)\n out = StringIO()\n t.write(out, format='ascii.html', htmldict={'raw_html_cols': 'a'})\n expected = \"\"\"\\\n \n x\n <em>y</em>\n \"\"\"\n assert expected in out.getvalue()\n\n # One column contains raw HTML (list input)\n out = StringIO()\n t.write(out, format='ascii.html', htmldict={'raw_html_cols': ['a']})\n assert expected in out.getvalue()\n\n # Two columns contains raw HTML (list input)\n out = StringIO()\n t.write(out, format='ascii.html', htmldict={'raw_html_cols': ['a', 'b']})\n expected = \"\"\"\\\n \n x\n y\n \"\"\"\n assert expected in out.getvalue()\n\n\n@pytest.mark.skipif('not HAS_BLEACH')\ndef test_raw_html_write_clean():\n \"\"\"\n Test that columns can contain raw HTML which is not escaped.\n \"\"\"\n import bleach # noqa\n\n t = Table([[''], ['

y

'], ['y']], names=['a', 'b', 'c'])\n\n # Confirm that