Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <div id="poetry">
  <p>白日依山尽</p>
  <p>黄河入海流</p>
  <p>欲穷千里目</p>
  <p>更上一层楼</p>
  <p>你是我的最爱怎会不明白</p>
  <p>春江潮水连海平,海上明月共潮生。</p>
</div>
            
          
!

CSS

            
              * {
  /* border: 1px solid blue; */
  margin: 0;
  padding: 0;
}
html {
  font-size: 21px;
}
body {
  padding: 1rem;
}
#poetry p {
  letter-spacing: 5px;
  margin-bottom: .5rem;
  display: flex;
}
#poetry p > ruby {
  width: 1.5rem;
}
#poetry p ruby rt {
  letter-spacing: normal;
  padding: 0 1px 0 0;
}
            
          
!

JS

            
              const log = console.log.bind(console)

const shengmu = ["b", "p", "m", "f", "d", "t", "l", "n", "g", "k", "h", "j", "q", "x", "zh?", "ch?", "sh?", "y", "w"]
const shengmuRegex =  shengmu.join('|')
const yunmuRegex = '(a|ā|á|ǎ|à|o|ō|ó|ǒ|ò|e|ē|é|ě|è|i|ī|í|ǐ|ì|u|ū|ú|ǔ|ù|ū|ú|ǔ|ù|er|ēr|ér|ěr|èr)+(ng|n)?'

const pySplit = function(_in) {
  const regex = new RegExp(`((${yunmuRegex}))(${shengmuRegex}?)`, 'g')
  const result = _in
  .replace(/[\'\.,,。]/g, ' ')
  .replace(regex, '$1 $5')
  .replace(/ {1,}/g, ' ')
  .toLowerCase()
  return result
}

const pNodes = document.querySelectorAll('#poetry > p')

var pinyin = [
  'Báirìyīshānjǐn',
  'huánghérùhǎiliú',
  'Yùqióngqiānlǐmù',
  'gèngshàngyīcénglóu',
  'Nǐshìwǒdezuì\'àizěnhuìbùmíngbái',
  'Chūnjiāngcháoshuǐliánhǎipíng,hǎishàngmíngyuègòngcháoshēng.'
]

const len = pNodes.length
for (let idx = 0; idx < len; idx++) {
  const node = pNodes[idx]
  const nodeText = node.textContent
  const nodeLen = nodeText.length

  const py = pySplit(pinyin[idx])

  let parsedNodes = []
  const textArray = nodeText.split('')
  const pyArray = py.split(' ')
  const textLen = textArray.length
  let pyIdx = 0
  for (let idx = 0; idx < textLen; idx++) {
    const text = textArray[idx]
    if (/[ \'\.,。,]/.test(text)) {
      parsedNodes.push(`<ruby>${text}<rt>&nbsp;</rt></ruby>`)
    } else {
      parsedNodes.push(`<ruby>${text}<rt>${pyArray[pyIdx]}</rt></ruby>`)
      pyIdx++
    }
  }
  node.innerHTML = parsedNodes.join('')
}
            
          
!
999px

Console