-
- 헤더 행 렌더링, 테이블
- 행이 행이 시작
!
이있는 경우 표는
- 속성 그것으로
=
저장되어있는 경우 각 행
- 찾기 찾기 각 헤더 가져 오기 및 렌더링
- 그렇지 않으면, 그것은 정상적인 행
- 테이블을 렌더링 각 셀 렌더링 : 모두 함께 조각을 넣어, 반환을
https://jsfiddle.net/n1dp3fcs/2/
var attrs = "", headers = "", rows = "";
function renderTables(wiki) {
wiki.replace(findTable, parseTable);
var HTML = "<table" + (attrs ? " " + attrs : "") + ">" +
(headers ? "<thead>" + headers + "</thead>" : "") +
(rows ? "<tbody>" + rows + "</tbody>" : "") +
"</table>";
attrs = headers = rows = "";
return HTML;
}
var findTable = /\{\|\s*(.*?)\s*\|\}/g,
parseTable = function(match, content) {
Array.prototype.forEach.call(content.split(newRow), renderRow);
};
var newRow = /\s*\|-\s*(?:\|\s*)?/g,
renderRow = function(content) {
console.log("tr", content, arguments);
if (content.indexOf("=") !== -1) { console.log("attrs"); attrs += content; }
else if (content[0] === "!") { console.log("th"); headers += "<tr>" + content.replace(findHeader, renderHeader) + "</tr>"; }
else { console.log("td"); rows += "<tr>" + content.replace(findCol, renderCol) + "</tr>"; }
};
var findHeader = /\s*!\s*([^!]+?)(?=\s*!|$)/g, renderHeader = "<th>$1</th>";
var findCol = /(?:^\s*|\s*\|\s*)([^\|]+?)(?=\s*\||$)/g, renderCol = "<td>$1</td>";
링크 된 파일은 무엇입니까? 위키를 html로 변환합니까? 그렇지 않다면, 왜 그것을 전혀 사용하지 않습니까? – Whothehellisthat
위키 백을 html로 변환하지 않지만 나머지는 변환합니다. 위키를 변환 할 수 있도록 여기에 함수를 추가해야합니다. –
오, 알겠습니다. 우리가 시작하기 전에 전체 라이브러리를 파싱하는 대신 문제에 집중할 수 있도록 정규식과 대치 함수 또는 기타 무엇이 필요한지 알려주는 것이 낫지 않습니까? – Whothehellisthat