Skip to content
This repository was archived by the owner on Jul 12, 2020. It is now read-only.

Use 'string' library to generate panel header's id#89

Merged
yamgent merged 1 commit intoMarkBind:masterfrom
nusjzx:import-string-module
Jul 31, 2018
Merged

Use 'string' library to generate panel header's id#89
yamgent merged 1 commit intoMarkBind:masterfrom
nusjzx:import-string-module

Conversation

@nusjzx
Copy link

@nusjzx nusjzx commented Jul 30, 2018

What is the purpose of this pull request? (put "X" next to an item, remove the rest)

• [ ] Documentation update
• [X] Bug fix
• [ ] New feature
• [ ] Enhancement to an existing feature
• [ ] Other, please explain:

Fixes MarkBind/markbind#392.

What is the rationale for this request?
The MarkBind repo is using markdown-it-anchor to generate the ids for Markdown heading, and it uses the string library. For consistency, we should use the same library for vue-strap.

What changes did you make? (Give an overview)
Import the string library, use it to generate the ids instead of using our own regex.

Testing instructions:

  1. npm install
  2. run npm run build in vue-strap repo
  3. copy vue-strap.min.js to markbind repo
  4. test on 2103 website.
    eg: search "unsafe"

@yamgent yamgent changed the title Import string module Use 'string' module to generate panel header's id Jul 30, 2018
@yamgent yamgent changed the title Use 'string' module to generate panel header's id Use 'string' library to generate panel header's id Jul 30, 2018
@yamgent yamgent modified the milestone: v2.0.1-markbind.17 Jul 30, 2018
@yamgent
Copy link
Member

yamgent commented Jul 30, 2018

As discussed, fix doesn't work with MarkBind/markbind#392 (comment).

src/Panel.vue Outdated
const panelHeaderText = jQuery(this.headerContent).wrap('<div></div>').parent().find(':header').text();
this.$refs.cardContainer.setAttribute('id', string(panelHeaderText).slugify().toString());
} else if(this.$refs.headerWrapper.innerHTML) {
this.$refs.cardContainer.setAttribute('id', jQuery(this.$refs.headerWrapper.innerHTML).wrap('<div></div>').parent().find(':header')[0].id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this cause an error if there is no header at all?

Maybe try something like this instead?

const header = this.$refs.headerWrapper.innerHTML).wrap('<div></div>').parent().find(':header');
if (header.length > 0) {
  this.$refs.cardContainer.setAttribute('id', header[0].id);
}

src/Panel.vue Outdated

if (this.headerContent) {
const panelHeaderText = jQuery(this.headerContent).wrap('<div></div>').parent().find(':header').text();
this.$refs.cardContainer.setAttribute('id', string(panelHeaderText).slugify().toString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you will still need to check if (panelHeaderText) {, otherwise it is possible for the id to be blank.

@yamgent yamgent modified the milestone: v2.0.1-markbind.17 Jul 30, 2018
Copy link
Member

@yamgent yamgent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above. If you have made the changes, do remember to push them to your branch.

src/Panel.vue Outdated
this.$refs.cardContainer.setAttribute('id', string(panelHeaderText).slugify().toString());
}
} else if(this.$refs.headerWrapper.innerHTML) {
const header = this.$refs.headerWrapper.innerHTML).wrap('<div></div>').parent().find(':header');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line doesn't compile (it should be jQuery(this.$refs.headerWrapper.innerHTML)?)

src/Panel.vue Outdated

if (this.headerContent) {
const panelHeaderText = jQuery(this.headerContent).wrap('<div></div>').parent().find(':header').text();
if(panelHeaderText) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have a space after if: if (panelHeaderText) {

src/Panel.vue Outdated
if(panelHeaderText) {
this.$refs.cardContainer.setAttribute('id', string(panelHeaderText).slugify().toString());
}
} else if(this.$refs.headerWrapper.innerHTML) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue: should have space after if.

Copy link
Member

@yamgent yamgent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine now. You can squash the commits now.

@nusjzx nusjzx force-pushed the import-string-module branch from 140593b to 8b5d16f Compare July 31, 2018 03:35
@yamgent
Copy link
Member

yamgent commented Jul 31, 2018

Not sure what happened, but I can't get it to work now? It now shows this error on the console:

TypeError: Cannot read property 'innerHTML' of undefined
    at o.mounted (vue-strap.min.js:37)
    at _t (vue.min.js:6)
    at Object.insert (vue.min.js:6)
    at A (vue.min.js:6)
    at hn.__patch__ (vue.min.js:6)
    at hn._update (vue.min.js:6)
    at hn.<anonymous> (vue.min.js:6)
    at St.get (vue.min.js:6)
    at new St (vue.min.js:6)
    at hn.$mount (vue.min.js:6)

Also the commit message can be a bit better (can just be the same as the PR title).

@nusjzx nusjzx force-pushed the import-string-module branch from dc5458f to 25b946e Compare July 31, 2018 05:03
Copy link
Member

@yamgent yamgent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still cannot jump to tutorial-timetable-tutor-roletimesvenue. I checked the source and apparently the ID is not generated?

src/Panel.vue Outdated
if (panelHeaderText) {
this.$refs.cardContainer.setAttribute('id', string(panelHeaderText).slugify().toString());
}
} else if (this.$refs.innerHTML) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be this.$refs.headerWrapper.innerHTML?

@nusjzx nusjzx force-pushed the import-string-module branch from 25b946e to cad5f67 Compare July 31, 2018 05:49
@yamgent yamgent added this to the v2.0.1-markbind.17 milestone Jul 31, 2018
@yamgent yamgent merged commit 2af0d7f into MarkBind:master Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search: Scrolling to heading after page load does not work, if heading contains a colon symbol

2 participants