Docsify: It does not search inside tables

Created on 18 Jul 2018  路  12Comments  路  Source: docsifyjs/docsify

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 :))))

wontfix

Most helpful comment

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

All 12 comments

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 :))

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'

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,

Just confirming that there is no fix for this.

I would also like to see this fixed.

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

Awesome thank you.

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

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

Any update on this issue being fixed by the PR?

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anikethsaha picture anikethsaha  路  3Comments

nothingrandom picture nothingrandom  路  5Comments

Jadyli picture Jadyli  路  3Comments

satu0king picture satu0king  路  3Comments

dialex picture dialex  路  4Comments