Back template

mail@pastecode.io avatar
unknown
html
a year ago
1.9 kB
1
Indexable
Never
<!-- Prettify by @pranavdeshai: Basic (back)

Version: 0.1.1
Readme: https://github.com/pranavdeshai/anki-prettify
Links:
- Reddit: https://www.reddit.com/user/Various_Breadfruit48
- GitHub: https://github.com/pranavdeshai
- Buy Me a Coffee: https://www.buymeacoffee.com/pranavdeshai
- Ko-fi: https://ko-fi.com/pranavdeshai

-->
<div class="prettify-flashcard">
  <div class="prettify-deck">{{Deck}}</div>
  <div class="prettify-field prettify-field--front">{{edit:rand-alg:Front}}</div>
  <hr class="prettify-divider prettify-divider--answer" id="answer" />
  <div class="prettify-field prettify-field--back">{{edit:Back}}</div>
  {{#Tags}}
  <div class="prettify-tags">{{clickable:Tags}}</div>
  {{/Tags}}
</div>

<script>
  // Split hierarchical tags
  var tagsContainerEl = document.querySelectorAll('.prettify-tags > *')
  if (tagsContainerEl.length > 0) {
    var tags = []
    tagsContainerEl.forEach((tagEl) => {
      tagEl.classList.add('prettify-tag')
      tags.push(tagEl.innerHTML)
      tags.forEach((tag) => {
        var childTag = tag.split('::').filter(Boolean)
        tagEl.innerHTML = childTag[childTag.length - 1].trim()
      })
    })
  } else {
    tagsContainerEl = document.querySelector('.prettify-tags')
    var tags = tagsContainerEl.innerHTML.split(' ').filter(Boolean)
    var html = ''
    tags.forEach((tag) => {
      var childTag = tag.split('::').filter(Boolean)
      html +=
        "<span class='prettify-tag'>" +
        childTag[childTag.length - 1] +
        '</span>'
    })
    tagsContainerEl.innerHTML = html
  }

  // Breadcrumbs to current deck
  var deckEl = document.querySelector('.prettify-deck')
  var subDecks = deckEl.innerHTML.split('::').filter(Boolean)
  html = []
  subDecks.forEach((subDeck) => {
    html.push("<span class='prettify-subdeck'>" + subDeck + '</span>')
  })
  deckEl.innerHTML = html.join('&nbsp;/&nbsp;')
</script>