blob: c5150ddd86d259e7f90426413fc18735e26d669c [file] [log] [blame]
// Copyright 2017 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io';
import 'package:markdown/markdown.dart';
/// Scrapes links in a markdown document.
class LinkScraper {
/// Extracts links from the given [file].
Iterable<String> scrape(String file) {
final List<Node> nodes =
final _Visitor visitor = _Visitor();
for (Node node in nodes) {
return visitor.links;
class _Visitor implements NodeVisitor {
static const String _key = 'href';
final Set<String> links = <String>{};
bool visitElementBefore(Element element) {
if (element.attributes.containsKey(_key)) {
return true;
void visitElementAfter(Element element) {}
void visitText(Text text) {}