question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suggestions for allowing content editors to center justify a tags content.

See original GitHub issue

Do you have any suggestions for how mobildoc could allow users to center text?

or

Is there any way text-align: center; can be placed on elements?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
internalfxcommented, Jun 15, 2018

I have solved this for my users with the following ugly hack…

  toggleAlign: function (type) {
      if (!this.editor.hasCursor()) {
        return
      }

      let activeType = null
      let marker = this.editor.range.head.marker
      let parent = marker.parent
      let head = parent.headPosition()
      let tail = parent.tailPosition()
      let range = head.toRange(tail)
      this.editor.selectRange(range)

      let alignments = ['div-left', 'div-center', 'div-right', 'div-justify']
      for (let alignment of alignments) {
        if (this.activeMarkupTags.includes(alignment)) {
          activeType = alignment.split('-')[1]
        }
      }

      if (activeType != null) {
        this.editor.run((editor) => {
          editor.toggleMarkup('div')
        })
      }

      if (activeType !== type) {
        this.editor.run((editor) => {
          let markup = editor.builder.createMarkup('div', {style: `text-align: ${type};`})
          editor.toggleMarkup(markup)
        })
      }

      this.editor.selectRange(tail.toRange())
    }
  }

Which also required these modifications…


import * as tagNames from 'mobiledoc-dom-renderer/dist/commonjs/mobiledoc-dom-renderer/utils/tag-names'
import { VALID_ATTRIBUTES, VALID_MARKUP_TAGNAMES } from 'mobiledoc-kit/dist/commonjs/mobiledoc-kit/models/markup'

tagNames.isValidMarkerType = function () {
  return true
}

VALID_ATTRIBUTES.push('style')
VALID_ATTRIBUTES.push('target')
VALID_ATTRIBUTES.push('class')
VALID_ATTRIBUTES.push('alt')

VALID_MARKUP_TAGNAMES.push('small')
VALID_MARKUP_TAGNAMES.push('div')

I realize this totally breaks compatibility and portability of mobiledoc, but those were never my reasons for using it.

Thank you for the taking the time to respond.

0reactions
sdhullcommented, Jul 3, 2018

I finally figured it out! I’ll add it here for posterity (and any other ember.js devs who happen upon this issue): For some reason, ember-mobiledoc-dom-renderer namespaces the mobiledoc-dom-renderer, so the following works to override the isValidMarkerType method:

import * as tagNames from 'ember-mobiledoc-dom-renderer/mobiledoc-dom-renderer/utils/tag-names';

tagNames.isValidMarkerType = function() { return true; }; // for renderer
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Center Text & Headers in CSS Using the Text-Align ...
To center text in CSS, use the text-align property and define it with ... inline CSS to the div to center-align the content...
Read more >
text-justify | CSS-Tricks
The text-justify property in CSS is a companion to the text-align property that is used to set the justification method of text when...
Read more >
How to right-align and justify-align in Markdown?
If you need to justify whole document like me, then add p { text-align: justify; } to the CSS. Additionally you can also...
Read more >
Align text left or right, center text, or justify text on a page
Align the edges of your to the left, center, right, or justified, or vertically to the top, center, or bottom between margins.
Read more >
Beginner's Guide: How to Center Align a Video in WordPress
How to Center Align Video in WordPress Content Editor; How to Center ... Here's what your embed code would look like with the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found