西藏巴青项目

extract-gis-sections.mjs 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import fs from 'fs'
  2. import path from 'path'
  3. import os from 'os'
  4. const x = fs.readFileSync(path.join(os.tmpdir(), 'gis-doc-raw.xml'), 'utf8')
  5. function strip(chunk) {
  6. return chunk
  7. .replace(/<w:tab[^>]*\/>/g, '\t')
  8. .replace(/<\/w:p>/g, '\n')
  9. .replace(/<[^>]+>/g, '')
  10. }
  11. const terms = [
  12. 'cmmapgl.accessToken',
  13. 'setAccessToken',
  14. '地图密钥',
  15. '2.3 地图组件',
  16. 'new cmmapgl.Map',
  17. 'NavigationControl',
  18. 'GeoJSON',
  19. '准备步骤',
  20. '基本准备'
  21. ]
  22. for (const t of terms) {
  23. let idx = 0
  24. let n = 0
  25. while (n < 3) {
  26. const found = x.indexOf(t, idx)
  27. if (found < 0) break
  28. console.log(`\n==== ${t} #${n + 1} ====`)
  29. console.log(strip(x.slice(found, found + 2000)))
  30. idx = found + t.length
  31. n++
  32. }
  33. }
  34. const markers = ['2.2 地图密钥', '2.3 地图组件', '准备步骤', '基本准备', 'cmmapgl.Map']
  35. for (const m of markers) {
  36. const i = x.indexOf(m)
  37. if (i < 0) continue
  38. console.log(`\n######## SECTION ${m} ########`)
  39. console.log(strip(x.slice(i, i + 12000)))
  40. }