Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It does not search inside tables #582

Closed
saioacoder opened this issue Jul 18, 2018 · 12 comments · Fixed by #1015
Closed

It does not search inside tables #582

saioacoder opened this issue Jul 18, 2018 · 12 comments · Fixed by #1015
Labels

Comments

@saioacoder
Copy link

saioacoder commented Jul 18, 2018

Hi :)

I find out that the search tool doesn't search inside a table and I have texts inside them that need to be searchable.

Is this an issue? Or is it something that I am missing?

This is my search configuration:

search: {
	  paths: 'auto',
	  placeholder: 'Buscar ...',
	  noData: 'No hay resultados',
	  depth: 2,
},

By the way, I love Docsify, it makes my life easier :))))

@saioacoder
Copy link
Author

saioacoder commented Jul 18, 2018

Hii again

I am not an expert on javascript, but I have found a not very pretty solution. I am not sure if it is correct, but it works better than before.

I have changed getIndex() function:

function genIndex(path, content, router, depth) {
  if ( content === void 0 ) content = '';

  var tokens = window.marked.lexer(content);
  var slugify = window.Docsify.slugify;
  var index = {};
  var slug;
  var result;

  tokens.forEach(function (token) {
    if (token.type === 'heading' && token.depth <= depth) {
      slug = router.toURL(path, {id: slugify(token.text)});
      index[slug] = {slug: slug, title: token.text, body: ''};
    } else {
      if (!slug) {
        return
      }
      if (!index[slug]) {
        index[slug] = {slug: slug, title: '', body: ''};
      } else if (index[slug].body) {
        index[slug].body += '\n' + (token.text || '');
      } else {
        if(token.type === 'table'){
          token.cells.forEach(function (rows) {
            rows.forEach(function(cell) {
               result += cell + '\n';
            });
          });
        }
        index[slug].body = result;
      }
    }
  });
  slugify.clear();
  return index
}

Maybe someone could improve it and check if it works as it should.

Thankssss :))

@A-Circle-Zhang
Copy link

function genIndex(path, content, router, depth) {
  if ( content === void 0 ) content = '';

  var tokens = window.marked.lexer(content);
  var slugify = window.Docsify.slugify;
  var index = {};
  var slug;

  tokens.forEach(function (token) {
    if (token.type === 'heading' && token.depth <= depth) {
      slug = router.toURL(path, {id: slugify(token.text)});
      index[slug] = {slug: slug, title: token.text, body: ''};
    } else {
      if (!slug) {
        return
      }
      if (!index[slug]) {
        index[slug] = {slug: slug, title: '', body: ''};
      } else {
        if(!token.text){
          if(token.type === 'table'){
            token.text = '';
            token.cells.forEach(function (rows) {
              rows.forEach(function(cell) {
                token.text += cell + '\n';
              });
            });
          }
        }
        index[slug].body = (index[slug].body ? index[slug].body + token.text : token.text) + '\n';
      }
    }
  });
  slugify.clear();
  return index
}

this is my code,

the real problem is token.text not exist when token.type === 'table'

@phenomen
Copy link

One year later bug still exist :(
I have a lot of data in the tables and search not being able to look through it is really sad,

@wjhrdy
Copy link

wjhrdy commented Apr 5, 2019

Just confirming that there is no fix for this.

@melloware
Copy link

I would also like to see this fixed.

@rbpclub
Copy link

rbpclub commented Apr 16, 2019

I think I've made a fix at least for tables based on @saioaRed code I'll submit a pull request.

@melloware
Copy link

Awesome thank you.

@melloware
Copy link

@rbpclub Any update on this PR? I am really interested in getting this feature in.

@wjhrdy
Copy link

wjhrdy commented Apr 18, 2019

Hey Sorry, I just realized I commented from an alt account. I am working on the PR.

@wjhrdy
Copy link

wjhrdy commented Apr 18, 2019

#824

@melloware
Copy link

Any update on this issue being fixed by the PR?

@stale
Copy link

stale bot commented Feb 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants